当前位置:网站首页>Recursive processing - subproblem
Recursive processing - subproblem
2022-07-26 05:54:00 【Study and pursue high efficiency】
First : What is a subproblem
That is to put the overall problem , Can be concentrated
For example, look for the left and right of the tree
It can be regarded as looking One node The left node Right node
Recursion processing subproblem
5. The detected value is value Does the element of exist
The recursive thought of subproblem : The principle is to analyze only one root node
The principle is to analyze only one root node
The analysis is as follows :
analysis A node
If A The value of the node is key
Then the return A node
Otherwise, traverse the left node
If the value returned by the left node is not empty Then return the return value
If the return value of the left node is null then Traverse the right node
If the return value of the right node is not empty Then return the return value
Otherwise, it will directly return null
// The detected value is value Does the element of exist
TreeNode find(TreeNode root, char val) {
if(root == null) return null;
if(root.val == val) {
return root;
}
TreeNode ret1 = find(root.left,val);
if(ret1 != null) {
return ret1;
}
TreeNode ret2 = find(root.right,val);
if(ret2 != null) {
return ret2;
}
return null;
}
边栏推荐
- The refurbishment and counterfeiting of chips have made people feel numb
- Flex layout
- 知识沉淀一:架构师是做什么?解决了什么问题
- ES Cluster in Red status: what about write & delete operations?
- Development projects get twice the result with half the effort, a large collection of open source STM32 driver Libraries
- A trick to teach you to easily understand Potter's map
- Full binary tree / true binary tree / complete binary tree~
- ERROR: Could not open requirements file: [Errno 2] No such file or directory: ‘requirments.txt’
- Kingbasees SQL language reference manual of Jincang database (8. Function (10))
- 金仓数据库 KingbaseES SQL 语言参考手册 (8. 函数(十))
猜你喜欢

Unity2d animator cannot create transition

Introduction to Chinese text error correction task

Etcd database source code analysis - cluster membership changes log

对接微信支付(二)统一下单API

Redis事务

知识沉淀一:架构师是做什么?解决了什么问题

vagrant下载速度慢的解决方法
![[论文笔记] 面向网络语音隐写的抗分组丢失联合编码](/img/ca/95476b6d4b5765f5fde82cbeda577e.png)
[论文笔记] 面向网络语音隐写的抗分组丢失联合编码

Talking about the practice of software defect management

金仓数据库 KingbaseES SQL 语言参考手册 (8. 函数(十))
随机推荐
Efficient, reliable and safe open source solution for serial communication
How can red star Macalline design cloud upgrade the traditional home furnishing industry in ten minutes to produce film and television level interior design effects
金仓数据库 KingbaseES SQL 语言参考手册 (7. 条件表达式)
A trick to teach you to easily understand Potter's map
语法泛化三种可行方案介绍
Unity Profiler
Redis transaction
Redis persistence AOF
Kingbasees SQL language reference manual of Jincang database (8. Functions (XI))
The refurbishment and counterfeiting of chips have made people feel numb
CANoe-XML在Test Modules中的应用
leetcode-Array
Jincang database kingbasees SQL language reference manual (5. Operators)
Solve vagrant's error b:48:in `join ': incompatible character encodings: GBK and UTF-8 (encoding:: Compatib
Mysql45 talking about global lock, table lock and row lock
How to name the project version number? Looks like cow b
Three graduates, three years of experience in embedded software
ERROR: Could not open requirements file: [Errno 2] No such file or directory: ‘requirments.txt’
LNMP architecture
金仓数据库 KingbaseES SQL 语言参考手册 (10. 查询和子查询)
