当前位置:网站首页>Niuke-top101-bm38
Niuke-top101-bm38
2022-07-25 20:45:00 【A fish that eats cats】
import java.util.*;
/* * public class TreeNode { * int val = 0; * TreeNode left = null; * TreeNode right = null; * } */
public class Solution {
/** * * @param root TreeNode class * @param o1 int integer * @param o2 int integer * @return int integer */
boolean sign = false;
public int lowestCommonAncestor (TreeNode root, int o1, int o2) {
// write code here
ArrayList<Integer> list1 = new ArrayList<>();
ArrayList<Integer> list2 = new ArrayList<>();
dfs(root, o1, list1);
sign = false;
dfs(root, o2, list2);
int res = 0;
for(int i = 0; i < list1.size() && i < list2.size(); i++){
int x = list1.get(i);
int y = list2.get(i);
if(x == y){
res = list1.get(i);
}else{
break;
}
}
return res;
}
public void dfs(TreeNode root, int target, ArrayList<Integer> path){
// Sentenced to empty
if(root == null || sign == true)
return;
path.add(root.val);
if(root.val == target){
sign = true;
return;
}
//dfs Traverse
dfs(root.left, target, path);
dfs(root.right, target, path);
if(sign == true)
return;
// to flash back
path.remove(path.size() - 1);
}
}
边栏推荐
- [today in history] July 18: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal
- Clickhouse notes 02 -- installation test clickvisual
- Has baozi ever played in the multi merchant system?
- MPI learning notes (II): two implementation methods of matrix multiplication
- Leetcode-155: minimum stack
- 476-82(322、64、2、46、62、114)
- Remote monitoring solution of intelligent electronic boundary stake Nature Reserve
- leetcode-6129:全 0 子数组的数目
- Wokerman custom write log file
- Force deduction ----- calculate the money of the force deduction bank
猜你喜欢

Kubernetes进阶部分学习笔记
![[today in history] July 18: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal](/img/7d/7a01c8c6923077d6c201bf1ae02c8c.png)
[today in history] July 18: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal

Success factors of software R & D effectiveness measurement

leetcode-6125:相等行列对
![[advanced mathematics] [3] Application of differential mean value theorem and derivative](/img/a9/3b024dbbb201bee4eed6c9f6ce3001.png)
[advanced mathematics] [3] Application of differential mean value theorem and derivative

Kubernetes advanced part learning notes

The database empties the table data and makes the primary key start from 1
![[MCU] 51 MCU burning those things](/img/fa/8f11ef64a18114365c084fff7d39f6.png)
[MCU] 51 MCU burning those things
![[advanced mathematics] [8] differential equation](/img/83/b6b07540e3cf6d6433e57447d42ee9.png)
[advanced mathematics] [8] differential equation
![[today in history] July 7: release of C; Chrome OS came out;](/img/a6/3170080268a836f2e0973916d737dc.png)
[today in history] July 7: release of C; Chrome OS came out; "Legend of swordsman" issued
随机推荐
KEGG通路的从属/注释信息如何获取
[advanced mathematics] [6] differential calculus of multivariate functions
"Shallow in and shallow out" MySQL and InnoDB [it is recommended to collect and share]
[tensorrt] trtexec tool to engine
Remote - basic principle introduction
Chapter VI modified specification (SPEC) class
Using the OAP aspect causes the controller to be called repeatedly
Online XML to JSON tool
Increase swap space
[cloud native] use of Nacos taskmanager task management
Explain the principle of MySQL master-slave replication in detail
LeetCode通关:哈希表六连,这个还真有点简单
Arrow parquet
Character function and string function (2)
leetcode-6126:设计食物评分系统
Compilation and operation of program
Based on pexels image material API, sort out the material resource library
[advanced mathematics] [3] Application of differential mean value theorem and derivative
Leetcode-79: word search
Explain in detail the principle of MySQL master-slave replication "suggestions collection"