class Solution {
public List<String> findRepeatedDnaSequences(String s) {
Set<String> set = new HashSet<>();
Set<String> answerSet = new HashSet<>();
for(int i=0;i<s.length()-9;i++) {
if(!set.add(s.substring(i,i+10))){
answerSet.add(s.substring(i,i+10));
}
}
ArrayList<String> list = new ArrayList<>(answerSet);
return list;
}
}여기서 자바가 기억할점은 이미 값이 있다면 false를 리턴한다.
'문제풀이' 카테고리의 다른 글
| [HackerRank] Sherlock and the Valid String (0) | 2022.10.03 |
|---|---|
| [HakerRank] Climbing the Leaderboard (0) | 2022.10.02 |
| [Leetcode] Game of Life Java (0) | 2021.06.18 |
| [프로그래머스] 압축 java (0) | 2021.05.06 |
| [백준] 퇴사2 Java (0) | 2021.04.15 |