Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
246aa1a
commit ad4d167
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |