题目地址:Jewels and Stones - LeetCode



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”.

Example 1:

Input: J = "aA", S = "aAAbbbb"
Output: 3

Example 2:

Input: J = "z", S = "ZZ"
Output: 0

Note:

  • S and J will consist of letters and have length at most 50.
  • The characters in J are distinct.

你会得到J代表珠宝类型的字符串,S代表你拥有的宝石。每个角色S都是你拥有的一种石头。你想知道你有多少宝石也是珠宝。

在这些信件J是保证不同,而在所有的字符J和S是字母。字母区分大小写,因此"a"被认为是不同类型的石头"A"。


python代码如下:

class Solution:def numJewelsInStones(self, J: str, S: str) -> int:count=0for i in S:if i in J:count+=1return count

Java代码如下:

class Solution {public int numJewelsInStones(String J, String S) {int count = 0;for (char s: S.toCharArray()) {if (J.contains(""+s)){count+=1;}}return count;}
}

LeetCode 771. Jewels and Stones--Java和Python解法--简单相关推荐

  1. LeetCode - 771. Jewels and Stones

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

  2. LeetCode 136. Single Number--异或--Java,C++,Python解法

    题目地址:Single Number - LeetCode Given a non-empty array of integers, every element appears twice excep ...

  3. 【博客搬家旧文】leetcode 771. Jewels and Stones

    今天开通了博客园 ,之前的博客就不用了.之后再陆陆续续把之前的博文重新放到这里来.有标题这个tag的都是搬运的旧博客的文章.希望在这里是个新的开始,嘻嘻. import java.util.Scann ...

  4. Leetcode 771. Jewels and Stones

    class Solution(object):def numJewelsInStones(self, J, S):""":type J: str:type S: str: ...

  5. LeetCode 316. Remove Duplicate Letters--贪心--Java,C++,Python解法

    题目地址:Number of Longest Increasing Subsequence - LeetCode 做这道题目前建议先做:Longest Increasing Subsequence - ...

  6. LeetCode 673. Number of Longest Increasing Subsequence--O(N log N )--Java,C++,Python解法

    题目地址:Number of Longest Increasing Subsequence - LeetCode 做这道题目前建议先做:Longest Increasing Subsequence - ...

  7. LeetCode 159. Longest Substring with At Most Two Distinct Characters --Java,C++,Python解法

    题目地址:Longest Substring with At Most Two Distinct Characters - LeetCode Given a string s , find the l ...

  8. LeetCode 746. Min Cost Climbing Stairs--动态规划--Java,C++,Python解法

    题目地址:Min Cost Climbing Stairs - LeetCode LeetCode 动态规划(Dynamic programming)系列题目:LeetCode 动态规划(Dynami ...

  9. LeetCode 122. Best Time to Buy and Sell Stock II--贪心--Java,C++,Python解法

    题目地址:Best Time to Buy and Sell Stock II - LeetCode Say you have an array for which the ith element i ...

最新文章

  1. linux内核杂记(8)-进程调度(3)
  2. python元组 字符串 字典 习题+总结
  3. mysql 函数substring_index()
  4. 轻松监听Azure service health 状态
  5. K-periodic Garland CodeForces - 1353E(暴力+贪心+dp)
  6. 数据结构--二叉树--路径 假设二叉树采用二叉链表方式存储, root指向根结点,node 指向二叉树中的一个结点, 编写函数 path,计算root到 node 之间的路径,(该路径包括root结
  7. leetcode 721. 账户合并(并查集)
  8. LoadRunner11支持的浏览器小结-Loadrunner11打不开IE浏览器的问题
  9. java baen转json 已经 json 转java bean 优秀博客分享
  10. mysql mongodb插件_FLinkX的Mongodb插件优化(三)
  11. Linux centosVMware shell编程 for循环、while循环、break跳出循环、continue结束本次循环、exit退出整个脚本...
  12. MYSQL 解压版5.7.12安装和客户端连接。
  13. educoder考试可以切屏吗_线上考试真的好多人作弊吗?
  14. oracle 父子级,oracle 父子关系
  15. 红米手机html文件,红米手机中ES文件浏览器无法删除SD卡中文件的解决办法-es文件浏览器...
  16. laravel-集合对象的销毁forget,重组values(),pluck ()方法
  17. 双连通分量的题目列表(一)
  18. 为什么有必要开发一个APP?
  19. 一个面试我的后端妹子问的405错误
  20. 2021软件工程保研经历

热门文章

  1. html float作用,CSS float相关详解
  2. bundle包是什么意思_iOS开发里的Bundle是个啥玩意?!
  3. 零基础入门学习Python(27)-文件2
  4. 青岛大学计算机学院生物信息研究组(苏晓泉团队)招生与招聘启事
  5. Nature | 人类胎盘应该真的是无菌的
  6. Ecol. Lett.:写给实践生态学家的β多样性分析指南 | 朝花夕拾
  7. 微生物组学研究的可再现性、可重现性、稳定性与普适性
  8. R语言max函数min函数计算各种数据对象最大值最小值实战
  9. 基于TF-IDF编码进行文本聚类分析:文档成对相似性计算、层次聚类(链接矩阵、树形图dendrogram绘制、聚类标签)
  10. 实体识别+entity resolution