일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Substring with Concatenation of All Words
- shiba
- Regular Expression
- 밴픽
- DWG
- 파이썬
- t1
- Python
- Convert Sorted List to Binary Search Tree
- Python Code
- 43. Multiply Strings
- 시바견
- 30. Substring with Concatenation of All Words
- 715. Range Module
- attribute
- data science
- 컴퓨터의 구조
- LeetCode
- 프로그래머스
- Generator
- Python Implementation
- 109. Convert Sorted List to Binary Search Tree
- concurrency
- iterator
- Class
- kaggle
- Protocol
- 운영체제
- Decorator
- 315. Count of Smaller Numbers After Self
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 |