开发者

Subsequences of a string in java with sorting

开发者 https://www.devze.com 2022-12-07 22:39 出处:网络
if someone could explain this code for me, and make an easier code to understand , i tried to sort this but no results, this one is complicated for a beginner and doesn\'t complete the job, i need sub

if someone could explain this code for me, and make an easier code to understand , i tried to sort this but no results, this one is complicated for a beginner and doesn't complete the job, i need subsequences of a string sorted like this : we give "abc", we get this :

  1. a
  2. ab
  3. ac
  4. abc
  5. b
  6. bc
  7. c

the code i found in a website

**buildSubsequences("abc");

public static List<String> buildSubsequences(String s) {
    List<String> result = new ArrayList<String>() ;
       
    char[] strSplit = s.toCharArray();
    
    for (int m = 1 ; m != 1<<strSplit.length ; m++) {
        for (int i = 0 ; i != strSplit.length ; i++) {
            if ((m & (1<<i)) != 0) {
                result.add(String.valueOf(strSplit[i]));
        System.out.print(strSp开发者_运维技巧lit[i]);
            }
        }
        System.out.print("\n");
    }

    return null;
}**
0

精彩评论

暂无评论...
验证码 换一张
取 消