Pirate
BAN USERSorry guys, my previous code had a little bug in that ....
Here is the updated version ...
public static void checkSubString(String full, String part){
int pos = 0;
for(int i=0,l=full.length(); i<l; ++i){
if(full.charAt(i) == part.charAt(pos)){
pos++;
if(pos == part.length()){
System.out.println("Found!");
System.exit(0);
}
}else if(pos > 0){
i -= pos;
pos = 0;
}
}
System.out.println("Not Found!");
}
public void checkSubString(String full, String part){
int pos = 0;
for(int i=0,l=full.length(); i<l; ++i){
if(full.charAt(i) == part.charAt(pos)){
pos++;
if(pos == part.length()){
System.out.println("Found!");
System.exit(0);
}
}else if(pos > 0){
i -= pos;
pos = 0;
}
}
System.out.println("Not Found!");
}
public void findMinSum(int[] x){
Arrays.sort(x);
String first = "";
String second = "";
for(int i=0,l=x.length; i<l; ++i){
if(i%2==0){
first+=x[i];
}else{
second+=x[i];
}
}
int num1 = Integer.parseInt(first);
int num2 = Integer.parseInt(second);
System.out.println("Numbers are : " + first + " and " + second);
System.out.println("Sum is : " + (num1+num2));
}
your first code fails for str = "aaabbc" and subStr = "aabc"
- Pirate December 03, 2013your updated code fails most often