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
- Counting
- Tree
- Data Structure
- string
- 구현
- sorting
- Class
- 코테
- simulation
- SQL
- database
- two pointers
- greedy
- dynamic programming
- implement
- 자바
- geometry
- array
- hash table
- 코딩테스트
- Stack
- bit manipulation
- Binary Tree
- Number Theory
- 파이썬
- Matrix
- Method
- Binary Search
- Math
- java
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1021. Remove Outermost Parentheses 본문
1. Input
1) String s
2. Output
1) s에서 가장 바깥 소괄호를 없앤 나머지를 반환
- s는 유효한 괄호들로 이루어져 있다.
3. Constraint
1) 1 <= s.length <= 10^5
2) s는 '('와 ')'로 이루어져 있다.
4. Example
Input: s = "(()())(())" -> Output: "()()()"
Input: s = "(()())(())(()(()))" -> Output: "()()()()(())"
Input: s = "()()" -> Output: ""
설명:
- “(()())”와 “(())”로 이루어져 있다. -> 가장 바깥 소괄호를 없애면 “()()”와 “()”이 된다.
- “(()())”와 “(())”와 “(()(()))”로 이루어져 있다. -> 가장 바깥 소괄호를 없애면 “()()”와 “()”와 “()(())”이 된다.
- “()”와 “()”로 이루어져 있다. -> 가장 바깥 소괄호를 없애면 둘다 “”이 된다.
5. Code
1) 첫 코드(2023/06/07)
class Solution {
public String removeOuterParentheses(String s) {
int count = 1, start = 0;
StringBuilder sb = new StringBuilder();
for(int i=1 ; i<s.length() ; i++){
char c = s.charAt(i);
if(c=='(') count++;
else count--;
if(count==0){
sb.append(s.substring(start+1, i));
start = i+1;
count = 0;
}
}
return sb.toString();
}
}
- 74%, 93%
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 1046. Last Stone Weight (0) | 2023.06.07 |
---|---|
[LeetCode/Easy] 1030. Matrix Cells in Distance Order (0) | 2023.06.07 |
[LeetCode/Easy] 1018. Binary Prefix Divisible By 5 (0) | 2023.06.07 |
[백준 온라인 저지] 14852. 타일 채우기 3 (0) | 2023.06.07 |
[백준 온라인 저지] 2133. 타일 채우기 (0) | 2023.06.07 |