当前位置:网站首页>Day 52 - tree problem
Day 52 - tree problem
2022-07-01 04:21:00 【Adaska】
The tree problem is more difficult than expected , Especially the problems involving string and dynamic programming , I feel that it is difficult to understand just the solution to the problem , In addition, I feel uneasy recently because I haven't heard anything about my own affairs due to the transfer of other colleagues , Efficiency is reduced . From tomorrow on, you should put your mind right , Improve learning efficiency , Don't affect your progress , After all, there is still a long way to go , It's also very difficult , I feel like I have entered the binary tree since I began to brush the questions , Start building websites , The whole difficulty has been greatly improved , It is no longer just a fragmented time that can be easily completed , It takes more time to concentrate , It's also easier to feel frustrated and tired , But tiredness is tiredness , Still don't want to give up .
Today's progress :
1. Insist on brushing questions , Listen to the online class tomorrow , Although the problem is stuck , Still try to keep the progress , Can also start nginx The environment of
2. Insist to take exercise
3. Keep recording the little prince
4. Keep records
Learning notes :
1.93. Restore IP Address
It works IP Address It's just four integers ( Each integer is located in 0 To 255 Between the composition of , And it can't contain leading 0), Use... Between integers ‘.’ Separate .
for example :“0.1.2.201” and “192.168.1.1” yes It works IP Address , however “0.011.255.245”、“192.168.1.312” and “[email protected]” yes Invalid IP Address .
Given a string containing only numbers s , It is used to indicate a IP Address , Returns all possible valid IP Address , These addresses can be accessed through s Insert ‘.’ To form . you You can't Reorder or delete s Any number in . You can press whatever Return the answers in order .
Input :s = “25525511135”
Output :[“255.255.11.135”,“255.255.111.35”]
Their thinking : Use dfs Iterate over what happens to each combination of numbers , take IP The address is divided into four segments , Explore every possibility , If in 0-255 Within the scope of , Just add the result string , Otherwise, continue with the next recursion , If not obtained 4 individual IP Address , End the traversal ahead of time , encounter 0,0 It must be a IP Address .
class Solution {
final static int IP_COUNT=4;
List<String> res = new ArrayList<String>();
int[] segments = new int[IP_COUNT];
public List<String> restoreIpAddresses(String s) {
dfs(s, 0, 0);
return res;
}
public void dfs(String s, int segId, int segStart){
// End of traversal , get 4 individual IP Address
if(segId==IP_COUNT){
if(segStart==s.length()){
StringBuffer ipAddr = new StringBuffer();
for(int i=0; i<IP_COUNT; i++){
ipAddr.append(segments[i]);
if(i!=IP_COUNT-1){
ipAddr.append(".");
}
}
res.add(ipAddr.toString());
}
return;
}
// Not obtained 4 individual IP Address , End traversal ahead of time
if(segStart==s.length()){
return;
}
// encounter 0,0 It must be a IP Address
if(s.charAt(segStart)=='0'){
segments[segId] = 0;
dfs(s, segId+1, segStart+1);
}
// General situation , Go through everything
int addr = 0;
for(int segEnd=segStart; segEnd<s.length(); segEnd++){
addr = addr*10 + (s.charAt(segEnd)-'0');
if(0<addr && addr<=255){
segments[segId] = addr;
dfs(s, segId+1, segEnd+1);
}
else{
break;
}
}
}
}
After this , In fact, I am even more disappointed with the company , Although I have long realized that the so-called department change is just a delaying plan for my parents not to let me change my job , There is still a big gap between the really ideal work content and the environment , Of course, there are greater requirements for strength , Don't settle for the status quo , We must work hard to refuel , Keep going tomorrow !
边栏推荐
- JMeter learning notes 2 - brief introduction to graphical interface
- Coinbase in a bear market: losses, layoffs, stock price plunges
- Daily question - line 10
- Custom components in applets
- TASK04|数理统计
- It's settled! 2022 JD cloud summit of JD global technology Explorer conference see you in Beijing on July 13
- [TA frost wolf \u may- hundred talents plan] 1.2.3 MVP matrix operation
- After many job hopping, the monthly salary is equal to the annual salary of old colleagues
- 206. reverse linked list
- 431. encode n-ary tree as binary tree DFS
猜你喜欢

MySQL advanced -- you will have a new understanding of MySQL

Use of JMeter counters
![[ta- frost wolf \u may- hundred people plan] 2.2 model and material space](/img/93/95ee3d4389ffd227559dc8b3207e1d.png)
[ta- frost wolf \u may- hundred people plan] 2.2 model and material space

Volley parsing data shows networking failure

小程序中自定义组件

JS image path conversion Base64 format

DO280管理应用部署--RC

"Target detection" + "visual understanding" realizes the understanding of the input image

Embedded System Development Notes 79: why should I get the IP address of the local network card

【发送邮件报错】535 Error:authentication failed
随机推荐
674. longest continuous increasing sequence force buckle JS
283.移动零
slf4j 简单实现
Concurrent mode of different performance testing tools
Custom components in applets
Qt开发经验小技巧226-230
MallBook:后疫情时代下,酒店企业如何破局?
小程序中自定义组件
JMeter学习笔记2-图形界面简单介绍
What are permissions? What are roles? What are users?
All in one 1086: Jiaogu conjecture
【LeetCode】100. Same tree
[send email with error] 535 error:authentication failed
Rule method: number of effective triangles
How to ensure the idempotency of the high concurrency interface?
LeetCode 1380. Lucky number in matrix
Internet winter, how to spend three months to make a comeback
熊市下的Coinbase:亏损、裁员、股价暴跌
PageObject模式解析及案例
Browser top loading (from Zhihu)