当前位置:网站首页>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;
}
}边栏推荐
- PTA year of birth
- Is the fund of futures account safe? How to open an account?
- February 16, 2022 Daily: graph neural network self training method under distribution and migration
- Session layer of csframework, server and client (1)
- Vue uses keep alive to cache page optimization projects
- Key points on February 15, 2022
- Opencv map reading test -- error resolution
- Growing up in the competition -- (Guangyou's most handsome cub) Pikachu walking
- 徽商期货是正规期货平台吗?在徽商期货开户安全吗?
- The latest intelligent factory MES management system software solution
猜你喜欢

A database editing gadget that can edit SQLite database. SQLite database replaces fields. SQL replaces all values of a field in the database

Set the style of QT property sheet control

Extract the compressed package file and retrieve the password

Common design parameters of solid rocket motor

Data warehouse (3) star model and dimension modeling of data warehouse modeling

Domestic spot silver should be understood

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

Blue Bridge Cup real topic: the shortest circuit

Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)

必看,时间序列分析
随机推荐
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
PTA year of birth
Data query language (DQL)
Win10+vs2019 Community Edition compiling OpenSSL
Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
The latest software scheme of the intelligent information management system of the armed police force
How to learn automated testing?
[beauty detection artifact] come on, please show your unique skill (is this beauty worthy of the audience?)
Depth first search - DFS (burst search)
Length of learning and changing
540. Single element in ordered array
transform. Forward and vector3 Differences in the use of forward
What are the legal risks of NFT brought by stars such as curry and O'Neill?
Set the style of QT property sheet control
The 13th simulation problem of the single chip microcomputer provincial competition of the Blue Bridge Cup
Review Net 20th anniversary development and 51aspx growth
Static timing analysis (STA) in ic/fpga design
Definition of rotation axis in mujoco
To improve the efficiency of office collaboration, trackup may be the best choice
因子分析怎么计算权重?