zoukankan      html  css  js  c++  java
  • Java实现 LeetCode 131 分割回文串

    class Go{
        List<List<String>> result = new ArrayList<>();
        List<String> list = new ArrayList<>();
        char[] arr;
        String s;
        void core(int index){
            if (index == arr.length){
                result.add(new ArrayList<>(list));
                return;
            }
            for (int i = index; i < arr.length; i++){
                if (ishw(index,i)){
                    list.add(s.substring(index,i + 1));
                    core(i + 1);
                    list.remove(list.size() - 1);
                }
            }
        }
        boolean ishw(int left,int right){
            int L = left,R = right;
            while (L <= R){
                if (arr[L++] != arr[R--]){
                    return false;
                }
            }
            return true;
        }
        public List<List<String>> partition(String s) {
            arr = s.toCharArray();
            this.s = s;
            core(0);
            return result;
        }
    }
    public class Cutpalindrome {
        public static void main(String[] args) {
            Go g = new Go();
            System.out.println(g.partition("aacb"));
        }
    }
    
  • 相关阅读:
    bzoj3224
    [洛谷日报第62期]Splay简易教程 (转载)
    bzoj1588
    codeforces467C
    codeforces616B
    codeforces379C
    codeforces545C
    codeforces285C
    codeforces659C
    快读代码level.2
  • 原文地址:https://www.cnblogs.com/a1439775520/p/12947048.html
Copyright © 2011-2022 走看看