LeetCode [771] gems and stones

This is used for double, it determines whether the two strings are equal, are equal if the count is incremented.

class Solution {
    public int numJewelsInStones(String J, String S) {
        int c1 = J.length();
        int c2 = S.length();
        int m,n;
        int count = 0;
        for(m = 0;m <= c2-1;m++)
        {
            for(n = 0;n <= c1-1;n++)
            {
                String t = J.substring(n,n+1);
                String s1 = S.substring(m, m+1);
                if(s1.equals(t))
                {
                    count++;
                }
            }
        }
        return count;
    }
}

Note that you must use two strings are equal xx.equals (xx), can not be used ==

Guess you like

Origin www.cnblogs.com/wzwi/p/10929192.html