Skip to content

Commit

Permalink
srm_556_div2_250 simple
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwi-coder committed Dec 7, 2012
1 parent 246aa1a commit ad4d167
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions srm_556_div2_250.java
@@ -0,0 +1,22 @@
import java.lang.*;

public class ChocolateBar {
public int maxLength(String letters) {
int result = 1;
for (int i = 0; i < letters.length(); i++) {
for (int j = i+1; j <= letters.length(); j++) {
String temp = letters.substring(i,j);
if (isUnique(temp))
result = Math.max(temp.length(), result);
}
}
return result;
}

private boolean isUnique(String s) {
for (int i = 0; i < s.length(); i++)
for (int j = i+1; j < s.length(); j++)
if (s.charAt(i) == s.charAt(j)) return false;
return true;
}
}

0 comments on commit ad4d167

Please sign in to comment.