Skip to content

Commit 5337b3d

Browse files
committed
refine
1 parent 0f6efa5 commit 5337b3d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

ScrambleString.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,20 @@ public boolean isScramble(String s1, String s2) {
5454
}
5555

5656
for (int k = 0; k < 26; k++) {
57-
if (A[k] != 0) return false;
57+
if (A[k] != 0)
58+
return false;
5859
}
5960

6061
for (int i = 1; i < s1.length(); i++) {
61-
boolean result = isScramble(s1.substring(0, i), s2.substring(0, i)) && isScramble(s1.substring(i), s2.substring(i));
62-
result = result || (isScramble(s1.substring(0, i), s2.substring(s2.length() - i, s2.length())) && isScramble(s1.substring(i), s2.substring(0, s2.length() - i)));
63-
if (result) return true;
62+
boolean result = isScramble(s1.substring(0, i), s2.substring(0, i))
63+
&& isScramble(s1.substring(i), s2.substring(i));
64+
result = result
65+
|| (isScramble(s1.substring(0, i),
66+
s2.substring(s2.length() - i, s2.length())) && isScramble(
67+
s1.substring(i), s2.substring(0, s2.length() - i)));
68+
if (result)
69+
return true;
6470
}
6571
return false;
6672
}
67-
68-
public static void main(String[] args) {
69-
System.out.println(new ScrambleString().isScramble("aab", "bab"));
70-
}
7173
}

0 commit comments

Comments
 (0)