일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- git
- dotenv
- Python
- Clone
- VUE
- condition
- JavaScript
- TypeScript
- vue.js
- C++
- leetcode
- property
- webpack
- BOJ
- nginx
- machine learning
- security
- var
- scss
- C#
- type
- bash
- generic
- npm
- vuetify
- loop
- 보안
- AI
- 앙상블
- docker
Archives
- Today
- Total
ice rabbit programming
[LeetCode] May Challenge 3 - Ransom Note 본문
728x90
https://leetcode.com/problems/ransom-note/
Ransom Note - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
2번 문제와 비슷했는데, 이번엔 단순 포함이 아닌 문자의 사용 횟수와 관련된 문제였다. 카드 사용 문제와 비슷한 느낌이었다. 각 문자별로 카운트를 하고, 차감하는 식으로 구현하였다.
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
int counts[27];
for(int i=0;i<27;i++)
counts[i]=0;
for(char source: magazine)
counts[source-'a']++;
for(char compare: ransomNote)
if(--counts[compare-'a']<0) return false;
return true;
}
};
728x90
'PS > LeetCode' 카테고리의 다른 글
[LeetCode] May Challenge 8 - Valid Perfect Square (0) | 2020.05.10 |
---|---|
[LeetCode] May Challenge 5 - First Unique Character in a String (0) | 2020.05.05 |
[LeetCode] Delete Duplicate Emails (0) | 2020.05.03 |
[LeetCode] May Challenge 2 - Jewels and Stones (0) | 2020.05.03 |
[LeetCode] Second Highest Salary (0) | 2020.05.01 |