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
- sorting
- 코딩테스트
- Binary Search
- greedy
- Tree
- 구현
- Method
- geometry
- 코테
- dynamic programming
- java
- Number Theory
- SQL
- Counting
- 자바
- two pointers
- database
- Class
- Stack
- array
- Math
- string
- Binary Tree
- simulation
- implement
- 파이썬
- hash table
- Matrix
- bit manipulation
- Data Structure
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 2315. Count Asterisks 본문
1. Input
1) String s
- s에는 |이 있는데, 2개씩 짝지어 존재한다.
2. Output
1) s에서 | | 사이에 있는 것을 제외한 나머지 *의 개수를 반환
3. Constraint
1) 1 <= s.length <= 1000
2) s에 있는 |는 항상 짝수개 존재한다.
3) s는 영어 소문자, |, *로 이루어져 있다.
4. Example
Input: s = "l|*e*et|c**o|*de|" -> Output: 2
설명: s에서 짝지어 존재하는 | 사이를 지우면 "l||c**o||"이 되고, 남은 문자열에서 *의 개수는 2개이므로 2를 반환한다.
5. Code
1) 첫 코드(2022/07/01)
int n = 0;
int count = 0;
for(int i=0 ; i<s.length() ; i++){
char c = s.charAt(i);
if(c=='|')
n++;
if(n%2==0 && c=='*')
count++;
} // for i
return count;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 2341. Maximum Number of Pairs in Array (0) | 2023.01.16 |
---|---|
[LeetCode/Easy] 2319. Check if Matrix Is X-Matrix (0) | 2023.01.16 |
[LeetCode/Easy] 2299. Strong Password Checker II (0) | 2023.01.16 |
[LeetCode/Easy] 2283. Check if Number Has Equal Digit Count and Digit Value (0) | 2023.01.16 |
[LeetCode/Easy] 2278. Percentage of Letter in String (0) | 2023.01.16 |