티스토리 뷰

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;
    }
};
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
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
글 보관함