Advertisement
ffpaladin

Finding whether string has repeated chars

Mar 3rd, 2014
149
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //finding if a string has repeated chars
  2. // no additional data structures
  3.  
  4. public class HelloWorld{
  5.  
  6.      public static void main(String []args){
  7.         System.out.println(charComp("7536481"));
  8.      }
  9.      
  10.      /*public static Boolean unique (String s){
  11.         if (s.length() > 100)
  12.             return false;
  13.         else
  14.             return charComp(s);
  15.      }*/
  16.      
  17.      public static Boolean charComp(String s){
  18.         if (s.isEmpty())
  19.             return true;
  20.        
  21.         char c = s.charAt(0);
  22.         System.out.println(c);
  23.         int index = s.indexOf(c,1);
  24.         System.out.println(index);
  25.        
  26.         if (index!=-1)
  27.             return false;
  28.         else
  29.             return(charComp(s.substring(1)));
  30.            
  31.      }
  32. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement