当前位置:网站首页>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;
}
}边栏推荐
- Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)
- The new server is packaged with the source code of H5 mall with an operation level value of several thousand
- Mysql database design
- Htt [ripro network disk link detection plug-in] currently supports four common network disks
- Irradiance, Joule energy, exercise habits
- Definition of rotation axis in mujoco
- JS how to convert a string with a delimiter into an n-dimensional array
- Key points on February 15, 2022
- Computer network interview assault
- . Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
猜你喜欢

Samba basic usage

Localization through custom services in the shuttle application

Gold, silver and four job hopping, interview questions are prepared, and Ali becomes the champion

Operation of cmake under win

Depth first search - DFS (burst search)

Good looking UI mall source code has been scanned, no back door, no encryption

Classpath classpath

Penetration practice vulnhub range Nemesis

How to retrieve the password for opening Excel files

PTA year of birth
随机推荐
To improve the efficiency of office collaboration, trackup may be the best choice
Xia CaoJun ffmpeg 4.3 audio and video foundation to engineering application
APK签名流程介绍[通俗易懂]
transform. Forward and vector3 Differences in the use of forward
Quick foundation of group theory (5): generators, Kelley graphs, orbits, cyclic graphs, and "dimensions" of groups?
Explain in detail the process of realizing Chinese text classification by CNN
Oracle TRUNC function processing date format
Penetration practice vulnhub range Nemesis
Develop those things: add playback address authentication to easycvr platform
Domestic spot silver should be understood
Is the fund of futures account safe? How to open an account?
Mujoco's biped robot Darwin model
Good looking UI mall source code has been scanned, no back door, no encryption
SCP -i private key usage
Easycvr accesses the equipment through the national standard gb28181 protocol. What is the reason for the automatic streaming of the equipment?
Bug of QQ browser article comment: the commentator is wrong
Can hero sports go public against the wind?
PCL learning materials
Computer network interview assault
Apk signature process introduction [easy to understand]