Short and Sweet <Java>


#1

public class Solution {
public ArrayList<ArrayList> partition(String a) {
ArrayList<ArrayList> r = new ArrayList<ArrayList>();
comb(a,r,new ArrayList());
return r;
}

public void comb(String s, ArrayList<ArrayList<String>> r,ArrayList<String> t)
{
    if(s.length()==0)
    {
        r.add(new ArrayList<>(t));
        return;
    }
    // if(s.length()==1)
    // {
    //     t.add(s);
    //     s="";
    //     comb(s,r,t);
    // }
    for(int i=1;i<=s.length();i++)
    {
        if(isPali(s.substring(0,i)))
        {   
            t.add(s.substring(0,i));
            String rs = s.substring(i);
            comb(rs,r,t);
            t.remove(t.size()-1);
        }
    }
}

public boolean isPali(String s)
{
    int l =0,r=s.length()-1;
    while(l<r)
    {
        if(s.charAt(l)==s.charAt(r))
        {
            l++;
            r--;
        }
        else{
            return false;
        }
    }
    return true;
}

}


#2

its not even compiling