在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);
}
}
以上。