Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- 위상정렬
- 코딩테스트
- generic class
- Sort
- javascript
- js
- 가상컴퓨팅
- 개발자취업
- 공개키 암호화
- mysql
- 코딩테스트준비
- LeetCode
- Algorithm
- sql
- spring
- 크루스칼
- Java
- 알고리즘
- 99클럽 #코딩테스트준비 #개발자취업 #항해99 #til
- 자료구조
- 항해99
- dbms
- 정렬
- 99클럽
- til
- python
- 코테
- jsp
- DB
- JPA
Archives
- Today
- Total
PLOD
[Leetcode] 187. Repeated DNA Sequences 본문
🔗 문제 링크
https://leetcode.com/problems/repeated-dna-sequences/
Repeated DNA Sequences - LeetCode
Can you solve this real interview question? Repeated DNA Sequences - The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'. * For example, "ACGAATTCCG" is a DNA sequence. When studying DNA, it is useful to identify r
leetcode.com
✅ 코드
import java.util.*;
import java.io.*;
class Solution {
public List<String> findRepeatedDnaSequences(String s) {
Set<String> seen = new HashSet<>();
Set<String> repeated = new HashSet<>();
for(int i = 0; i <= s.length() - 10; i++){
String sub = s.substring(i, i + 10);
if(seen.contains(sub)){
repeated.add(sub);
}else{
seen.add(sub);
}
}
return new ArrayList<>(repeated);
}
}
💡 배운 점 & 느낀 점
1. String sub = s.substring(i,i+10) → 문자열을 슬라이싱 할 때, 사용한다.
2. seen.contains(sub) → 특정 원소를 가지고 있는 지 여부 판단(Set 자료구조는 순서와 중복을 허용하지 않는다)
- 자주 쓰는 메서드
- set.add("A");
- set.contains("A");
- set.remove("A");
-
set.size();
3. return new ArrayList<>(repeated) → Set 자료구조를 ArrayList 자료구조로 변환(같은 자료형 일때 변환이 가능하다)
'대외 활동 및 IT 지식 > 알고리즘 문제 풀이 정리' 카테고리의 다른 글
| [Programmers] 조건에 맞는 개발자 찾기(MySQL) (0) | 2026.03.23 |
|---|---|
| [백준] 평행선(2358) (0) | 2026.03.23 |
| [Leetcode] 2283. Check if Number Has Equal Digit Count and Digit Value (0) | 2026.03.20 |
| [백준] 좌표 압축(18870) (0) | 2026.03.09 |
| [백준] 파일 정리(20291) (0) | 2026.03.09 |
Comments