leetcode 771. Jewels and Stones

  在csdn上看了那么久别人的博客,今天也开始开通自己的博客了。就算是作为找工作路上的一个总结。有些代码放在eclipse上写过就算了,就算有问题也很难再去翻出来看,还不如放在这里,以后也方便查看。不去面试不知道自己的水平有多渣渣,今天开始刷leetcode以及昨天网易的笔试题,都是在eclipse上运行没毛病最后还是不能完全accept。出现的error还没找到解决方法,放在这里以后也许有一天就突然懂了。



import java.util.Scanner;

class Solution {
    public static int numJewelsInStones(String J, String S) {
       int count=0;
	     for(int i=0; i<J.length(); i++){
	    	 for(int j=0; j<S.length(); j++){
	    		 if(J.charAt(i) == S.charAt(j))
	    			 count++;
	            }
	        }
	        return count;
	    }
    }
    
    public static void main(String[] args){
        Scanner in =new Scanner(System.in);
	     String J=in.nextLine();
	     String S=in.nextLine();
	     int count=numJewelsInStones(J, S);
	     System.out.println(count);
    }
} 

  以上是看到题目第一反应的做法,在eclipse上运行没毛病,放到leetcode上之后报了一个编译错误:

Line 16: error: class, interface, or enum expected

  后来把程序改成不让用户输入之后就过了,第一次刷leetcode还不太清楚为啥,先放在这里以后再来看看。

class Solution {
    public static int numJewelsInStones(String J, String S) {
      int count=0;
	     for(int i=0; i<J.length(); i++){
	    	 for(int j=0; j<S.length(); j++){
	    		 if(J.charAt(i) == S.charAt(j))
	    			 count++;
	            }
	        }
	        return count;
    }
    
    public static void main(String[] args){
	     String J="aA";
	     String S="aaAbbb";
	     int count=numJewelsInStones(J, S);
	     System.out.println(count);
    }
}
  以上。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值