题解:宝石与石头(771)

版权声明:本文为博主原创文章,转载时注明出处,附加链接即可。 https://blog.csdn.net/cswhit/article/details/81709474

好久没做算法题了,找个网站做做练习一下,网站链接:LeetCode

这道题很简单,一个暴力就出来了

class Solution {
    public int numJewelsInStones(String J, String S) {
        int count =0;
		int h = J.length();
		for(int i=0;i<h;++i) {
			for(int j=S.indexOf(J.charAt(i));j<=S.lastIndexOf(J.charAt(i));++j) {
				if(j<0)
					break;
				if(J.charAt(i)==S.charAt(j))
					++count;
			}
		}
		return count;
    }
}

猜你喜欢

转载自blog.csdn.net/cswhit/article/details/81709474
今日推荐