Untitled

mail@pastecode.io avatar
unknown
java
3 years ago
1.1 kB
3
Indexable
Never
import java.util.*;
public class HelloWorld{
    
    static List<String> al = new ArrayList<>();

     public static void main(String []args){
        String s = "wzwaz";
        findsubsequences(s, "");
        int x = leftRight();
        System.out.println(x);
     }
     
     private static void findsubsequences(String s,
                                         String ans)
    {
        if (s.length() == 0) {
            al.add(ans);
            return;
        }
 
        findsubsequences(s.substring(1), ans + s.charAt(0));
 
        findsubsequences(s.substring(1), ans);
    }
    
    private static int leftRight() {
        for (String s : al) {
            if (s.length() > 0 && leftrotate(s, 1).equals(rightrotate(s, 1))) {
                return s.length();
            }
        }
        return 0;
    }
    
    static String leftrotate(String str, int d)
    {
            String ans = str.substring(d) + str.substring(0, d);
            return ans;
    }
 
    static String rightrotate(String str, int d)
    {
            return leftrotate(str, str.length() - d);
    }
}