当前位置:网站首页>6. < tag backtracking and cutting problems > lt.131 Split palindrome string
6. < tag backtracking and cutting problems > lt.131 Split palindrome string
2022-06-09 12:01:00 【Caicai's big data development path】
lt.131. Split palindrome string
[ Case needs ]

[ Thought analysis ]


[ Code implementation ]
class Solution {
List<List<String>> lists = new ArrayList<>();
List<String> path = new ArrayList<>();
public List<List<String>> partition(String s) {
//
backTracking(s, 0);
return lists;
}
//1. Recursive function : String cutting ,
public void backTracking(String s, int startIndex){
//2. The end condition
//startIndex Is the cutting line
if(startIndex >= s.length()){
lists.add(new ArrayList<>(path));
return;
}
//3. Single layer recursive logic
for(int i = startIndex; i < s.length(); i++){
if(isParlindrome(s, startIndex, i)){
String str = s.substring(startIndex, i + 1);
path.add(str);
}else{
continue;
}
backTracking(s, i + 1);
path.remove(path.size() - 1);
}
}
public boolean isParlindrome(String s, int left, int right){
while(left < right){
if(s.charAt(left) != s.charAt(right)){
return false;
}else{
++left;
--right;
}
}
return true;
}
}

边栏推荐
- 09 | 中台落地第四步:中台的建设与接入(Delivery)
- 由于没有远程桌面授权服务器可以提供许可证
- How to insert the video monitoring memory card into the Yuntai pro of Xiaomi smart camera
- HEVC之HM学习02
- 中国科学院院刊 | 包云岗:加速发展关键核心技术,必须把握技术发展的自身规律
- dotnet core 也能协调分布式事务啦!
- Real questions and answers of comprehensive knowledge of system integration project management engineer in the second half of 2021
- Answers to six basic questions of security assessment for commercial password applications
- No remote desktop license server can provide licenses
- Windows远程时提示CredSSP加密数据库修正
猜你喜欢

Win10 your organization has turned off automatic update. How to solve the problem?

HEVC之HM学习01

Windows远程时提示CredSSP加密数据库修正

04 | 万事预则立:中台建设前必须想清楚的四个问题

【管理知多少】中文“其他”、英文“OTHER”、日文“その他”.......

Use of component El scrollbar

【转载】搞懂G1垃圾收集器
![[patch analysis] cve-2016-8610: patch analysis of](/img/cb/77578a38c2c907c6ee83ac0f70df88.png)
[patch analysis] cve-2016-8610: patch analysis of "SSL death alert" vulnerability leading to denial of service

08 | middle stage landing step 3: middle stage planning and design

Focus on DNS: analysis of ISC bind
随机推荐
3. < tag backtracking, combination and pruning > lt.17 Letter combination of telephone number
10 | summary: summary of middle platform landing tool resources
4.<tag-回溯和组合及其剪枝>lt.39.组合总和 + lt.40. 组合总和 II dbc
1.<tag-回溯和组合及其剪枝>lt.77.组合 +剪枝 dyh
Focus on DNS: analysis of ISC bind
SIGIR 2022 | CMI:结合对比学习和多兴趣挖掘的微视频推荐
商用密码应用安全性评估
12. < tag binary tree and BST foundation > lt.701 Insert operation DBC in binary search tree
H3C Certified Network Engineer
No remote desktop license server can provide licenses
Go zero micro Service Practice Series (II. Service splitting)
你的微服务敢独立交付么?
接力AlphaFold!星药科技重磅发布TBind-开启分子蛋白复合物结构预测新纪元
Smart contract security guide for Web3 project
H3C Certified Wireless Internet expert
tag回溯-刷题预备知识-1. 回溯法模板, + lt.46. 全排列
iphone5s显示被停用了解决办法
spark 寫入doris太慢方案解决
On event loop
03 | definition of China Taiwan: what are we talking about when we talk about China Taiwan?