일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- data science
- Protocol
- Substring with Concatenation of All Words
- concurrency
- 109. Convert Sorted List to Binary Search Tree
- 43. Multiply Strings
- Convert Sorted List to Binary Search Tree
- kaggle
- Regular Expression
- 시바견
- 밴픽
- 컴퓨터의 구조
- iterator
- 파이썬
- Decorator
- 30. Substring with Concatenation of All Words
- Python Code
- Class
- 운영체제
- t1
- LeetCode
- 715. Range Module
- shiba
- Python Implementation
- attribute
- Generator
- 프로그래머스
- 315. Count of Smaller Numbers After Self
- DWG
- Python
Archives
- Today
- Total
Scribbling
[Java 101] 242. Valid Anagram with HashMap 본문
class Solution {
public boolean isAnagram(String s, String t) {
if (s.length() != t.length())
return false;
Map<Character, Integer> counter1 = new HashMap<>();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
counter1.merge(c, 1, Integer::sum);
}
Map<Character, Integer> counter2 = new HashMap<>();
for (int i = 0; i < t.length(); i++) {
char c = t.charAt(i);
counter2.merge(c, 1, Integer::sum);
}
for (Character c : counter1.keySet()) {
if (!counter1.get(c).equals(counter2.get(c)))
return false;
}
return true;
}
}
'Computer Science > Java' 카테고리의 다른 글
[Java 101] 49. Group Anagrams with HashMap, StringBuilder (0) | 2023.02.14 |
---|---|
[Java 101] 1. Two Sum with HashMap as a counter (0) | 2023.02.14 |
[Java 101] 217. Contains Duplicate with HashSet, Arrays.stream (0) | 2023.02.14 |
[Java 101] LeetCode: 2. Add Two Numbers (0) | 2023.02.14 |
[Java 101] LeetCode: 15. 3Sum with 2D List (0) | 2023.02.14 |