当前位置:网站首页>Force buckle day33
Force buckle day33
2022-07-01 18:33:00 【Congruence_ vinegar】
589、N Preorder traversal of a cross tree
Given a n The root node of the fork tree root
, return Of its node value The former sequence traversal .n Fork tree In the input sequence traversal serialization representation , Each group of child nodes consists of null values null
Separate .
/*
// Definition for a Node.
class Node {
public int val;
public List<Node> children;
public Node() {}
public Node(int _val) {
val = _val;
}
public Node(int _val, List<Node> _children) {
val = _val;
children = _children;
}
};
*/
class Solution {
public List<Integer> preorder(Node root) {
List<Integer>list=new ArrayList<>();
pre(root,list);
return list;
}
public void pre(Node root,List<Integer>list){
if(root==null) return ;
list.add(root.val);
for(Node kid:root.children){
pre(kid,list);
}
}
}
559、N The maximum depth of the fork tree
Given a N Fork tree , Find its maximum depth .
Maximum depth is the total number of nodes on the longest path from the root node to the farthest leaf node .
N The input of the fork tree is represented by sequence traversal serialization , Each group of child nodes is separated by null values ( See example ).
/*
// Definition for a Node.
class Node {
public int val;
public List<Node> children;
public Node() {}
public Node(int _val) {
val = _val;
}
public Node(int _val, List<Node> _children) {
val = _val;
children = _children;
}
};
*/
class Solution {
public int maxDepth(Node root) {
if(root==null) return 0;
int max=0;
for(Node kid:root.children){
int depth=maxDepth(kid);
max=Math.max(max,depth);
}
return max+1;
}
}
1380、 The lucky number in the matrix
To give you one m * n
Matrix , The number in the matrix Each are not identical . Please press arbitrarily Return all the lucky numbers in the matrix in order .
Lucky number refers to the elements in the matrix that meet the following two conditions at the same time :
- The smallest of all elements in the same row
- The largest of all elements in the same column
Two dimensional array : 3 7 8
9 11 13
15 16 17
The minimum value per line is 3 、9 、15
The maximum value per column is 15、 16 、17
class Solution {
public List<Integer> luckyNumbers (int[][] matrix) {
int m=matrix.length;
int n=matrix[0].length;
int []min=new int[m];
int []max=new int[n];
Arrays.fill(min,Integer.MAX_VALUE);
Arrays.fill(max,Integer.MIN_VALUE);
List<Integer>list=new ArrayList<>();
for(int i=0;i<m;i++){// Traverse the rows of a two-dimensional array
for(int j=0;j<n;j++){// Traverse the columns of a two-dimensional array
min[i]=Math.min(min[i],matrix[i][j]);// Find the minimum value of each row , Fill in the array min in
max[j]=Math.max(max[j],matrix[i][j]);// Find the maximum value of each column , Fill in the array max in
}
}
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
if(matrix[i][j]==min[i]&&matrix[i][j]==max[j]){
list.add(matrix[i][j]);
}
}
}
return list;
}
}
边栏推荐
- SCP -i private key usage
- JS how to convert a string with a delimiter into an n-dimensional array
- [image denoising] matlab code for removing salt and pepper noise based on fast and effective multistage selective convolution filter
- Quick foundation of group theory (5): generators, Kelley graphs, orbits, cyclic graphs, and "dimensions" of groups?
- Easycvr accesses the equipment through the national standard gb28181 protocol. What is the reason for the automatic streaming of the equipment?
- When the fixed frequency artifact falls in love with multithreading | ros2 fixed frequency topic release demo
- EasyCVR通过国标GB28181协议接入设备,出现设备自动拉流是什么原因?
- Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
- 徽商期货是正规期货平台吗?在徽商期货开户安全吗?
- Step size of ode45 and reltol abstol
猜你喜欢
Source code of new campus errand / campus task platform on mutual station
[PHP foundation] realize the connection between PHP and SQL database
Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
t10_ Adapting to Market Participantsand Conditions
A database editing gadget that can edit SQLite database. SQLite database replaces fields. SQL replaces all values of a field in the database
This is the latest opportunity of the London bank trend
Operation of cmake under win
[image denoising] matlab code for removing salt and pepper noise based on fast and effective multistage selective convolution filter
Set the style of QT property sheet control
Domestic spot silver should be understood
随机推荐
L'ouverture d'un compte d'actions en ligne est - elle sécurisée? Fiable?
Localization through custom services in the shuttle application
[PHP foundation] realize the connection between PHP and SQL database
Leetcode 1380. Lucky numbers in the matrix (save the minimum number of each row and the maximum number of each column)
The latest software scheme of the intelligent information management system of the armed police force
Work and leisure suggestions of old programmers
An example of data analysis of an old swatch and an old hard disk disassembly and assembly combined with the sensor of an electromagnetic press
Localization through custom services in the shuttle application
Apache iceberg source code analysis: schema evolution
Extract the compressed package file and retrieve the password
What are the six steps of the software development process? How to draw software development flow chart?
Is online stock account opening safe? Is it reliable?
PCL learning materials
Wechat applet blind box - docking wechat payment
golang中的select详解
[beauty detection artifact] come on, please show your unique skill (is this beauty worthy of the audience?)
What is web application security testing technology?
Blue Bridge Cup real question: score statistics
Setting up a time server requires the client to automatically synchronize the time of the server at 9 a.m. every day
How to retrieve the password for opening Excel files