当前位置:网站首页>2022.6.24-----leetcode. five hundred and fifteen
2022.6.24-----leetcode. five hundred and fifteen
2022-06-26 03:47:00 【Lu 727】
List<Integer> ans;
Deque<TreeNode> q;
public List<Integer> largestValues(TreeNode root) {
ans=new ArrayList<>();
q=new ArrayDeque<>();
if(root!=null)
q.add(root);
bfs();
return ans;
}
// By layer Sequence traversal
void bfs(){
if(q.isEmpty()) return;
int max=Integer.MIN_VALUE;
int n=q.size();
for(int i=0;i<n;i++){
TreeNode cur=q.poll();
max=Math.max(max,cur.val);
if(cur.left!=null)
q.add(cur.left);
if(cur.right!=null)
q.add(cur.right);
}
ans.add(max);
bfs();
}
边栏推荐
- usb peripheral 驱动 - 枚举
- Ieda suddenly cannot find compact middle packages
- Do you want to add a key to the applet or for sequence?
- Mybatis的引入问题invalid
- 763. dividing alphabetic intervals
- ABP framework Practice Series (III) - domain layer in depth
- JS array array JSON de duplication
- js实现文字跑马灯效果
- EF core Basics
- Slide the menu of uni app custom components left and right and click switch to select and display in the middle
猜你喜欢
Cloud Computing Foundation -0
Non H5 end of uni app, regional setting of status bar on the top of mobile phone
Restful API interface design standards and specifications
Uni app custom drop-down selection list
C # knowledge structure
Uni app Baidu cloud realizes OCR ID card recognition
Kotlin quick start
Tupu software is the digital twin of offshore wind power, striving to be the first
Deletelater Usage Summary in QT
ABP framework Practice Series (II) - Introduction to domain layer
随机推荐
Evaluation - analytic hierarchy process
Is it safe to open a fund account? How to apply
Ieda suddenly cannot find compact middle packages
An error occurred using the connection to database 'on server' 10.28.253.2‘
I/O 虚拟化技术 — VFIO
“再谈”协议
Run multiple main functions in the clion project
HL7Exception: Can‘t XML-encode a GenericMessage. Message must have a recognized struct
虚拟化是什么意思?包含哪些技术?与私有云有什么区别?
Classic model alexnet
评价——层次分析
MySQL addition, deletion, query and modification (primary level)
[paper notes] supersizing self supervision: learning to grasp from 50K tries and 700 robot hours
Slide the menu of uni app custom components left and right and click switch to select and display in the middle
MySQL的视图
Andorid hide the title bar of the system
ABP framework
MySQL高级部分( 四: 锁机制、SQL优化 )
Asynctask multiple simultaneous use methods
Prism framework