描述

给定字符串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的更多相关文章

  1. LeetCode --> 771. Jewels and Stones

    Jewels and Stones You're given strings J representing the types of stones that are jewels, and S rep ...

  2. Leetcode#771.Jewels and Stones(宝石与石头)

    题目描述 给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石. J 中的字母不重复,J 和 S中的所有字 ...

  3. 【Leetcode】Jewels and Stones

    Jewels and Stones Description You're given strings J representing the types of stones that are jewel ...

  4. 【Leetcode_easy】771. Jewels and Stones

    problem 771. Jewels and Stones solution1: class Solution { public: int numJewelsInStones(string J, s ...

  5. 771. Jewels and Stones - LeetCode

    Question 771. Jewels and Stones Solution 题目大意:两个字符串J和S,其中J中每个字符不同,求S中包含有J中字符的个数,重复的也算 思路:Set记录字符串J中的 ...

  6. codechef Jewels and Stones 题解

    Soma is a fashionable girl. She absolutely loves shiny stones that she can put on as jewellery acces ...

  7. 771. Jewels and Stones

    You're given strings J representing the types of stones that are jewels, and S representing the ston ...

  8. [Swift]LeetCode771. 宝石与石头 | Jewels and Stones

    You're given strings J representing the types of stones that are jewels, and S representing the ston ...

  9. [LeetCode] Jewels and Stones 珠宝和石头

    You're given strings J representing the types of stones that are jewels, and S representing the ston ...

随机推荐

  1. CentOS 7 防火墙,端口开启命令

    1.  查看已打开的端口  # netstat -anp 2. 查看想开的端口是否已开 # firewall-cmd --query-port=8003/tcp   若此提示 FirewallD is ...

  2. js 判断输入的内容是否是整数

    需求简介:列表有一列排序,其值只能是整数,不能是小数,在js中判断,并给出提示 解决思路:在js中先获取表单的值,然后用isNaN,然后查一下怎么把小数排除在外.我靠( ‵o′)凸,这只能算是半路把! ...

  3. JSP 指令 脚本元素 表达式 声明

    一.page指令 1. 可以使用page指令来控制JSP转换器转换当前JSP页 面的某些方面.例如,可以告诉JSP用于转换隐式对象 out的缓冲器的大小.内容类型,以及需要导入的Java 类型,等等. ...

  4. java----AOP框架理解

    面向切面编程: 通过动态代理+加配置文件 目的解耦 给主逻辑添加一些修饰功能,但是不在主逻辑代码中进行修改,有点类似python中的装饰器,调用方法还是是通过接口的那个类来调用: import jav ...

  5. yii2 Menu组件的使用

    1.首先引入类 use yii\widgets\Menu; 2.配置组件 <?php echo Menu::widget([ //ul的样式以及相应的属性 'options' => ['c ...

  6. Jmeter测试demo

    复制代码,保存为.jmx文件 需要安装插件: JMeterPlugins-ExtrasLibs E:\软件\apache-jmeter-3.0\lib\ext <?xml version=&qu ...

  7. 步步为营-74-Request,Response和server的其他成员

    Request 1 Request.UrlReferrer 获取请求的来源 2 Request.UserHostAddress 获取访问者的IP地址 3 Request.Cookies 获取浏览器发送 ...

  8. K/3 Cloud Web API接口说明文

    K/3 Cloud Web API接口说明文 目的 三方集成,提供第三方系统与Cloud集成调用接口. 技术实现 HTTP + Json 提供标准接口 编号 名称 说明 1 Kingdee.BOS.W ...

  9. C#Enum用Tuple保存值绑定到前端的CheckBox

    //把数字转成枚举 public static T[] NumStringsToEnums<T>(string enumNumString ) //where T:Enum { if (s ...

  10. SQL Server索引误区使用建议

    常见的误区: 1.数据库不需要索引 2.主键总是聚集的 3.联机索引操作不引起阻塞 4.复合索引下列的顺序不重要 5.聚集索引以物理顺序存储 6.填充因子可以应用在索引的插入过程中 7.每个表应该有聚 ...