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
- SQL
- Math
- string
- java
- 코딩테스트
- hash table
- geometry
- implement
- array
- sorting
- two pointers
- database
- 구현
- Matrix
- Stack
- greedy
- Data Structure
- 파이썬
- simulation
- 코테
- dynamic programming
- Number Theory
- 자바
- Counting
- Tree
- Class
- Method
- Binary Search
- Binary Tree
- bit manipulation
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 2068. Check Whether Two Strings are Almost Equivalent 본문
코딩테스트 풀이/JAVA
[LeetCode/Easy] 2068. Check Whether Two Strings are Almost Equivalent
무지맘 2023. 1. 12. 09:201. Input
1) 문자열 word1
2) 문자열 word2
2. Output
1) 두 문자열이 almost equivalent라면 true, 아니면 false
// Almost Equivalent의 조건
- 두 문자열을 이루고 있는 각 문자들의 빈도 수의 차가 3 이하여야 한다.
3. Constraint
1) n == word1.length == word2.length
2) 1 <= n <= 100
3) word1과 word2는 영어 소문자로만 이루어져 있다.
4. Example
Input: word1 = "aaaa", word2 = "bccb" -> Output: false
설명:
- b와 c의 빈도수 차는 각각 2이므로 3 이하라서 괜찮다.
- a의 경우 word1에서는 4번 나오는데, word2에서는 0번 나온다. -> 4 - 0 > 3 이므로 false
5. Code
1) 첫 코드(2022/07/05)
int[] n = new int[26];
for(int i=0 ; i<word1.length() ; i++){
n[word1.charAt(i)-97]++;
n[word2.charAt(i)-97]--;
}
for(int i=0 ; i<26 ; i++)
if(Math.abs(n[i])>3)
return false;
return true;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 2103. Rings and Rods (0) | 2023.01.12 |
---|---|
[LeetCode/Easy] 2089. Find Target Indices After Sorting Array (0) | 2023.01.12 |
[LeetCode/Easy] 2057. Smallest Index With Equal Value (0) | 2023.01.12 |
[LeetCode/Easy] 2042. Check if Numbers Are Ascending in a Sentence (0) | 2023.01.12 |
[프로그래머스/Lv.1] 푸드 파이트 대회 (0) | 2023.01.11 |