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
- Tree
- array
- two pointers
- Binary Search
- Data Structure
- greedy
- simulation
- Matrix
- string
- Math
- 코테
- dynamic programming
- Method
- Binary Tree
- 파이썬
- SQL
- 구현
- Number Theory
- implement
- Counting
- Class
- Stack
- bit manipulation
- java
- 코딩테스트
- geometry
- sorting
- database
- hash table
- 자바
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 2278. Percentage of Letter in String 본문
1. Input
1) 문자열 s
2) 문자 letter
2. Output
1) s에서 letter가 차지하는 비중을 %로 나타낸 결과를 반환
- 소수 첫째 자리에서 버림한 결과를 반환한다.
3. Constraint
1) 1 <= s.length <= 100
2) s는 영어 소문자로 이루어져 있다.
3) letter에는 영어 소문자 1개가 담겨있다.
4. Example
Input: s = "foobar", letter = "o" -> Output: 33
설명: 2 / 6 * 100 = 33.333...이므로 33을 반환한다.
5. Code
1) 첫 코드(2022/06/17)
int count = 0;
for(int i=0 ; i<s.length() ; i++)
if(s.charAt(i) == letter)
count++;
return (int)(count * 100 / s.length());
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[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] 2269. Find the K-Beauty of a Number (0) | 2023.01.16 |
[LeetCode/Easy] 2264. Largest 3-Same-Digit Number in String (0) | 2023.01.16 |
[LeetCode/Easy] 2255. Count Prefixes of a Given String (0) | 2023.01.16 |