Skip to content

Commit

Permalink
feat(Code Challenge: hasDuplicate()): finish
Browse files Browse the repository at this point in the history
  • Loading branch information
101zh committed Nov 14, 2023
1 parent 6ae2353 commit 13d5d38
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/java/DuplicateCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

public class DuplicateCheck {
public static boolean hasDuplicate(String s) {
for (int i = 0; i < s.length(); i++) {
String curLetter = s.substring(i, i + 1);
for (int j = i + 1; j < s.length(); j++) {
if (curLetter.equals(s.substring(j, j + 1))) {
return true;
}
}
}

return false;
}

public static void main(String[] args) {
System.out.println(hasDuplicate("null")); // true
System.out.println(hasDuplicate("abc")); // false
System.out.println(hasDuplicate("abca")); // true
System.out.println(hasDuplicate("llun")); // true
String funstr = "~!@#$%^&*()_+`1234567890-=qwertyuiop[]\"QWERTYUIOP{}asdfghjkl;'ASDFGHJKL:zxcvbnm,./ZXCVBNM<>?";
System.out.println(hasDuplicate(funstr)); // false
}
}

0 comments on commit 13d5d38

Please sign in to comment.