Skip to content

Commit

Permalink
refine
Browse files Browse the repository at this point in the history
  • Loading branch information
mengli committed Jan 5, 2014
1 parent 0f6efa5 commit 5337b3d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions ScrambleString.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,20 @@ public boolean isScramble(String s1, String s2) {
}

for (int k = 0; k < 26; k++) {
if (A[k] != 0) return false;
if (A[k] != 0)
return false;
}

for (int i = 1; i < s1.length(); i++) {
boolean result = isScramble(s1.substring(0, i), s2.substring(0, i)) && isScramble(s1.substring(i), s2.substring(i));
result = result || (isScramble(s1.substring(0, i), s2.substring(s2.length() - i, s2.length())) && isScramble(s1.substring(i), s2.substring(0, s2.length() - i)));
if (result) return true;
boolean result = isScramble(s1.substring(0, i), s2.substring(0, i))
&& isScramble(s1.substring(i), s2.substring(i));
result = result
|| (isScramble(s1.substring(0, i),
s2.substring(s2.length() - i, s2.length())) && isScramble(
s1.substring(i), s2.substring(0, s2.length() - i)));
if (result)
return true;
}
return false;
}

public static void main(String[] args) {
System.out.println(new ScrambleString().isScramble("aab", "bab"));
}
}

0 comments on commit 5337b3d

Please sign in to comment.