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
- database
- hash table
- Binary Search
- array
- java
- Stack
- Data Structure
- Class
- simulation
- 구현
- 코딩테스트
- Binary Tree
- Method
- bit manipulation
- two pointers
- geometry
- Number Theory
- sorting
- 코테
- Tree
- 파이썬
- SQL
- Matrix
- Math
- dynamic programming
- greedy
- 자바
- Counting
- string
- implement
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1957. Delete Characters to Make Fancy String 본문
1. Input
1) String s
2. Output
1) s를 fancy string으로 만든 결과를 반환
- fancy string이란 같은 문자가 연속으로 3개 이상 나오지 않는 문자열을 말한다.
- 이때 s를 fancy string으로 만들기 위해 삭제한 문자의 개수가 최소가 되어야 한다.
3. Constraint
1) 1 <= s.length <= 10^5
2) s는 영어 소문자로 이루어져 있다.
4. Example
Input: s = "leeetcode" -> Output: "leetcode"
Input: s = "aaabaaaa" -> Output: "aabaa"
Input: s = "aab" -> Output: "aab"
5. Code
1) 첫 코드(2023/06/21)
class Solution {
public String makeFancyString(String s) {
StringBuilder sb = new StringBuilder();
int i = 0;
while(i<s.length()){
int j = i+1;
while(j<s.length() && s.charAt(j)==s.charAt(i)) j++;
for(int a=i ; a<Math.min(j,i+2) ; a++)
sb.append(s.charAt(a));
i = j;
}
return sb.toString();
}
}
- 52%, 29%