p*j
2 楼
输入一个字符串,返回所有字串,即"abc" -> {"a", "b", "c", "ab", "bc", "abc"}
。觉得写的好烂,大神们给提提意见,多谢!
public static ArrayList combinationsString(String s) {
ArrayList res = new ArrayList();
for (int i = 1; i <= s.length(); i++) {
dfs(s, 0, i, res);
}
return res;
}
private static void dfs(String s, int start, int resLength, ArrayList<
Character> res) {
if (resLength == 0) {
System.out.println(res.toString());
return;
}
if (start == s.length()) {
return;
}
res.add(s.charAt(start));
dfs(s, start + 1, resLength - 1, res);
res.remove(res.size() - 1);
dfs(s, start + 1, resLength, res);
}
public static void main(String[] args) {
String s = "abc";
combinationsString(s);
}
。觉得写的好烂,大神们给提提意见,多谢!
public static ArrayList
ArrayList
for (int i = 1; i <= s.length(); i++) {
dfs(s, 0, i, res);
}
return res;
}
private static void dfs(String s, int start, int resLength, ArrayList<
Character> res) {
if (resLength == 0) {
System.out.println(res.toString());
return;
}
if (start == s.length()) {
return;
}
res.add(s.charAt(start));
dfs(s, start + 1, resLength - 1, res);
res.remove(res.size() - 1);
dfs(s, start + 1, resLength, res);
}
public static void main(String[] args) {
String s = "abc";
combinationsString(s);
}
l*a
4 楼
你想返回的难道不是List?
I wonder whether "abc" can be stored in List
【在 p*********j 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: 输入一个字符串,返回所有字串,即"abc" -> {"a", "b", "c", "ab", "bc", "abc"}
: 。觉得写的好烂,大神们给提提意见,多谢!
: public static ArrayList combinationsString(String s) {
: ArrayList res = new ArrayList();
: for (int i = 1; i <= s.length(); i++) {
: dfs(s, 0, i, res);
: }
: return res;
: }
: private static void dfs(String s, int start, int resLength, ArrayList<
I wonder whether "abc" can be stored in List
【在 p*********j 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: 输入一个字符串,返回所有字串,即"abc" -> {"a", "b", "c", "ab", "bc", "abc"}
: 。觉得写的好烂,大神们给提提意见,多谢!
: public static ArrayList
: ArrayList
: for (int i = 1; i <= s.length(); i++) {
: dfs(s, 0, i, res);
: }
: return res;
: }
: private static void dfs(String s, int start, int resLength, ArrayList<
o*s
5 楼
介题不就是subset咩?
★ 发自iPhone App: ChineseWeb 8.7
【在 p*********j 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: 输入一个字符串,返回所有字串,即"abc" -> {"a", "b", "c", "ab", "bc", "abc"}
: 。觉得写的好烂,大神们给提提意见,多谢!
: public static ArrayList combinationsString(String s) {
: ArrayList res = new ArrayList();
: for (int i = 1; i <= s.length(); i++) {
: dfs(s, 0, i, res);
: }
: return res;
: }
: private static void dfs(String s, int start, int resLength, ArrayList<
★ 发自iPhone App: ChineseWeb 8.7
【在 p*********j 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: 输入一个字符串,返回所有字串,即"abc" -> {"a", "b", "c", "ab", "bc", "abc"}
: 。觉得写的好烂,大神们给提提意见,多谢!
: public static ArrayList
: ArrayList
: for (int i = 1; i <= s.length(); i++) {
: dfs(s, 0, i, res);
: }
: return res;
: }
: private static void dfs(String s, int start, int resLength, ArrayList<
相关阅读
请教OPT和H1b可以一起申请吗?请教一道behavioral的问题技术销售转什么方向好呢?周五dream公司Onsite,求祝福Bloomberg 非CS口的电面facebook纽约找人么[合集] M面完焦急等待中。。。。。大家看看我是个什么水平?常说的A家是amazon还是apple有没有比较适合0基础programmer的python学习网站推荐?请google内部朋友帮忙, 紧急求助, 在线等。。。A家 first phone interview今天收到拒绝信有人在玩 Facebook 的黑客杯吗?faculty面试工业界职位,如何比较好地回答这个问题? (转载)如何找CS工作请教湾区工程师的职位面试着装申请了bloomberg的好几个职位,是不是一个悲剧其他就悲剧?[合集] H1-pending F1-H1,律师要我立刻取消F1申请不走Eb-1的话, 身份多久能拿到?两个offer,去哪个