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
- array
- hash table
- Counting
- Stack
- bit manipulation
- Tree
- 코테
- 구현
- sorting
- database
- 코딩테스트
- two pointers
- Matrix
- Binary Search
- dynamic programming
- java
- 자바
- Method
- Binary Tree
- string
- geometry
- SQL
- Number Theory
- Math
- simulation
- Class
- 파이썬
- greedy
- implement
- Data Structure
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 383. Ransom Note 본문
1. Input
1) String ransomNote
2) String magazine
2. Output
1) magazine에 있는 알파벳들로 ransomNote를 만들 수 있다면 true를, 만들 수 없다면 false를 반환
3. Constraint
1) 1 <= ransomNote.length, magazine.length <= 10^5
2) ransomNote와 magazine은 영어 소문자로만 이루어져 있다.
4. Example
Input: ransomNote = "aa", magazine = "ab" -> Output: false
Input: ransomNote = "aa", magazine = "aab" -> Output: true
5. Code
1) 첫 코드(2023/02/14)
boolean answer = true;
int[] alphabets = new int[26];
for(int i=0 ; i<magazine.length() ; i++)
alphabets[magazine.charAt(i)-97]++;
for(int i=0 ; i<ransomNote.length() ; i++)
alphabets[ransomNote.charAt(i)-97]--;
for(int i=0 ; i<26 ; i++){
if(alphabets[i]<0){
answer = false; break;
}
}
return answer;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Medium] 384. Shuffle an Array (0) | 2023.02.15 |
---|---|
[프로그래머스/Lv.1] 가장 가까운 같은 글자 (0) | 2023.02.14 |
[LeetCode/Easy] 382. Linked List Random Node (0) | 2023.02.14 |
[프로그래머스/Lv.1] 크기가 작은 부분문자열 (0) | 2023.02.09 |
[프로그래머스/Lv.0] 외계어 사전 (0) | 2023.02.06 |