1038. Jewels And Stones
描述
给定字符串J代表是珠宝的石头类型,而S代表你拥有的石头.S中的每个字符都是你拥有的一个石头. 你想知道你的石头有多少是珠宝.
J中的字母一定不同,J和S中的字符都是字母。 字母区分大小写,因此"a"和"A"是不同的类型.
- S和J由字母组成且长度最大为50.
- J中字符各不相同.
您在真实的面试中是否遇到过这个题?
样例
样例 1:
输入: J = "aA", S = "aAAbbbb"
输出: 3
样例 2:
输入: J = "z", S = "ZZ"
输出: 0
Description
You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the stones you have are also jewels.
The letters in J are guaranteed distinct, and all characters in J and S are letters. Letters are case sensitive, so "a" is considered a different type of stone from "A".
S and J will consist of letters and have length at most 50.
The characters in J are distinct.
public class Solution {
/**
* @param J: the types of stones that are jewels
* @param S: representing the stones you have
* @return: how many of the stones you have are also jewels
*/
public int numJewelsInStones(String J, String S) {
// Write your code here
char[] jewelry = J.toCharArray();
char[] stone = S.toCharArray();
int res = 0;
for(int i=0; i<jewelry.length; i++){
for(int j=0; j<stone.length; j++){
if (jewelry[i] == stone[j]) {
res++;
}
}
}
return res;
}
}
1038. Jewels And Stones的更多相关文章
- LeetCode --> 771. Jewels and Stones
Jewels and Stones You're given strings J representing the types of stones that are jewels, and S rep ...
- Leetcode#771.Jewels and Stones(宝石与石头)
题目描述 给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石. J 中的字母不重复,J 和 S中的所有字 ...
- 【Leetcode】Jewels and Stones
Jewels and Stones Description You're given strings J representing the types of stones that are jewel ...
- 【Leetcode_easy】771. Jewels and Stones
problem 771. Jewels and Stones solution1: class Solution { public: int numJewelsInStones(string J, s ...
- 771. Jewels and Stones - LeetCode
Question 771. Jewels and Stones Solution 题目大意:两个字符串J和S,其中J中每个字符不同,求S中包含有J中字符的个数,重复的也算 思路:Set记录字符串J中的 ...
- codechef Jewels and Stones 题解
Soma is a fashionable girl. She absolutely loves shiny stones that she can put on as jewellery acces ...
- 771. Jewels and Stones
You're given strings J representing the types of stones that are jewels, and S representing the ston ...
- [Swift]LeetCode771. 宝石与石头 | Jewels and Stones
You're given strings J representing the types of stones that are jewels, and S representing the ston ...
- [LeetCode] Jewels and Stones 珠宝和石头
You're given strings J representing the types of stones that are jewels, and S representing the ston ...
随机推荐
- SpringBoot图片上传(二)
需求简介:做新增的时候,需要上传图片.(⊙o⊙)…这需求描述也太简单了吧,限制文件大小60*60 512kb ,第一次做,记录一下嗷,废话就不啰嗦了 上代码 代码: //html代码<div c ...
- Linux系统下目录的权限意义
访问者及其基本权限 Linux系统内的文件访问者有三种身份,分别是: a) 文件和文件目录的所有者: u---User(所有权);b) 文件和文件目录的所有者所在的组的用户: g---Group;c) ...
- 十六进制的ASCII码 "\u6cf0\u56fd" 解码成unicode
转码方法: C#: string a = "\u6cf0\u56fd"; string b = Encoding.UTF8.GetString(Encoding.UTF8.GetB ...
- kickstart-E
A题 简答模拟题 #include <iostream> #include<stdio.h> #include <set> #include <algorit ...
- 【SpringBoot】常用注解
@EnableAutoConfiguration 启动自动装载:使用了这个注解之后,所有引入的jar的starters都会被自动注入.这个类的设计就是为starter工作的. @RestControl ...
- 安装CentOS 7(转)
转载地址:https://www.cnblogs.com/wcwen1990/p/7630545.html CentOS7安装详解 本文基于vmware workstations进行CentOS7 ...
- 导出CSV乱码
导出CSV,无论是什么格式,excel打卡都是乱码 需要加上 echo "\xEF\xBB\xBF"; header("Content-Disposition:attac ...
- stl测试
以下测试都在学校电脑进行 我觉得应该比考试机器慢一点.. 1.map map的速度测出来和放入数值大小有很大关系 比如 #include <bits/stdc++.h> using nam ...
- word图片自动编号,前面加章节号
老实说很多人都没有系统性地学过WORD,毕竟所见即所得,就是学过也比较浅.那么在使用word写作论文时就会感到很烦,因为你想要控制好章节,这样很多的地方就可以按照这种章节自动编号,处理不同节的页眉和页 ...
- 【NPM】常见问题解决
问题列表 问题一:npm install 执行报错 npm ERR! Unexpected end of JSON input while parsing near '...ependencies&q ...