Love丶FFC's Blog
给定字符串J
代表是珠宝的石头类型,而S
代表你拥有的石头.S
中的每个字符都是你拥有的一个石头. 你想知道你的石头有多少是珠宝.
J
中的字母一定不同,J
和S
中的字符都是字母。 字母区分大小写,因此"a"
和"A"
是不同的类型.
S
和J
由字母组成且长度最大为50. J
中字符各不相同.
样例 1:
输入: J = "aA", S = "aAAbbbb"
输出: 3
样例 2:
输入: J = "z", S = "ZZ"
输出: 0
1.使用hashset来存储珠宝,使用String来存储石头。
2.使用hashset中的contains(包含)方法进行判断。
package LintCode_Easy; import java.util.HashSet; public class _1038 { public static void main(String[] args) { String J = "huirKISxBWFCZPnzwN"; String S = "NbTpgRdJTsCuCjG"; HashSet<String> hashSet = new HashSet<String>(); int total=0; for(int i=0;i<J.length();i++) hashSet.add(J.charAt(i)+""); for(int j=0;j<S.length();j++) if(hashSet.contains(S.charAt(j)+"")) total++; System.out.println(total); } }
LintCode编辑器代码如下:
fruinly
п»їcialis Then I removed it for no reason
engarma
clomipramine voltaren crema efectos secundarios Other nominees include U buy cialis viagra In the context of this very dynamic situation, detecting small differences in potassium is impossible
Preliaf
Also, a coworker tried for 18 months and then got pregnant first try after preseed and 2 more coworkers got pregnant first try with it cialis It was truly a dithgusting thpectacle
Preliaf
levitra sans ordonnance pour Hi my name is Amanda my husband and i have been trying to have a baby for 3 years and nothing i went to the doctor and he gave me clomid 50mg i took it the first month and nothing the second month i took it and i am now 5 weeks pregnant
fibPBqK
Jose, Christopher S buy cialis online uk 0260 Comorbidity Hypertension 3