티스토리 뷰
leetcode.com/problems/jewels-and-stones/
Jewels and Stones - 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
argument로 2개의 string을 input
함수는 2개의 string을 parameter로 받아와서, 첫번째 문자열의 원소별로 두번째 문자열의 원소와 같은것이 몇개 있는지를 return함.
2중 for문
class Solution {
public:
int numJewelsInStones(string jewels, string stones) {
int cnt = 0;
for (int i = 0; i < jewels.size(); i++) {
for (int j = 0; j < stones.size(); j++) {
if (jewels[i] == stones[j]) {
cnt++;
}
}
}
return cnt;
}
};
'알고리즘 문제 풀이' 카테고리의 다른 글
[알고리즘문제풀이] 릿코드 Sum of Unique Elements (0) | 2021.04.04 |
---|---|
[알고리즘문제] 릿코드 How Many Numbers Are Smaller Than the Current Number (0) | 2021.04.04 |
[알고리즘문제] 릿코드 Number of Good Pairs (0) | 2021.04.04 |
[알고리즘문제] 프로그래머스 큰수만들기 (0) | 2021.04.01 |
[알고리즘문제] 프로그래머스 K번째수 (0) | 2021.03.18 |