lintcode-1038. 珠宝和石头
- 题目描述
给定字符串J代表是珠宝的石头类型,而S代表你拥有的石头.S中的每个字符都是你拥有的一个石头. 你想知道你的石头有多少是珠宝.
J中的字母一定不同,J和S中的字符都是字母。 字母区分大小写,因此"a"和"A"是不同的类型.
- 算法思路
将J,S处理成list,再用两层for循环即可解决。
- code
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
"""
def numJewelsInStones(self, J, S):
# Write your code here
list_J = list(J)
list_S = list(S)
list_Z = []
for i in list_J:
for j in list_S:
if j == i:
list_Z.append(j)
n = len(list_Z)
return n
lintcode-1038. 珠宝和石头的更多相关文章
- [LeetCode] Jewels and Stones 珠宝和石头
You're given strings J representing the types of stones that are jewels, and S representing the ston ...
- 18.Jewels and Stones(珠宝和石头)
Level: Easy 题目描述: You're given strings J representing the types of stones that are jewels, and Sre ...
- [LeetCode] 771. Jewels and Stones 珠宝和石头
You're given strings J representing the types of stones that are jewels, and S representing the ston ...
- 1038. Jewels And Stones
描述 给定字符串J代表是珠宝的石头类型,而S代表你拥有的石头.S中的每个字符都是你拥有的一个石头. 你想知道你的石头有多少是珠宝. J中的字母一定不同,J和S中的字符都是字母. 字母区分大小写,因此& ...
- 771. Jewels and Stones珠宝数组和石头数组中的字母对应
[抄题]: You're given strings J representing the types of stones that are jewels, and S representing th ...
- lintcode算法周竞赛
------------------------------------------------------------第七周:Follow up question 1,寻找峰值 寻找峰值 描述 笔记 ...
- [LintCode]——目录
Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...
- Team Leader 你不再只是编码, 来炖一锅石头汤吧
h3{ color: #000; padding: 5px; margin-bottom: 10px; font-weight: bolder; background-color: #ccc; } h ...
- (lintcode全部题目解答之)九章算法之算法班题目全解(附容易犯的错误)
--------------------------------------------------------------- 本文使用方法:所有题目,只需要把标题输入lintcode就能找到.主要是 ...
随机推荐
- 使用GitHub搜索技巧
in:name example 名字中有"example"in:readme example readme中有"example"in:description e ...
- 2019 中至数据java面试笔试题 (含面试题解析)
本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.中至数据等公司offer,岗位是Java后端开发,因为发展原因最终选择去了中至数据,入职一年时间了,也成为了面 ...
- 深圳宝安图书馆官网错误 HTTP Status 500 - Servlet.init() for servlet spring threw exception
停留了一段时间没有动 打开https://www.balib.cn/balib/category/152 *********************************************** ...
- 手撕面试官系列(一):spring108道面试题合集
前言 想必各位程序员已经开始准备金九银十的秋招了,创建这个这个系列文章的目的就是为了帮助大家解决面试的问题,系列文章将会一直更新,大家如果觉得不错可以关注我并转发,让更多程序兄弟看到~接下来我们进入正 ...
- 阿里巴巴Java开发手册更新了!
自2017年,<阿里巴巴Java开发手册>发布,现已有超过260万位工程师下载及查阅手册,在数以千计的企业应用,手册成为受业界认可的开发规范. 昨天,<Java开发手册>再次更 ...
- Android-----CheckBox复选使用(实现简单选餐)
直接上代码: xml布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmln ...
- Vue 中 $nextTick() 的应用
Vue 在更新 DOM 时是异步执行的. 只要侦听到数据变化,Vue 将开启一个队列,并缓冲在同一事件循环中发生的所有数据变更.如果同一个 watcher 被多次触发,只会被推入到队列中一次.这种在缓 ...
- Process.Start可能无法选中指定文件的问题
简单的说是由于给定的文件路径中含有多余的斜杠(\),比如C:\a\b\\c.txt,在.NET类(比如File,FileInfo,Directory)中使用没有问题,但是如果使用Process.Sta ...
- CDA数据分析【第一章:数据分析概述】
一.数据分析行业发展 1.如何收集.保存.管理.分析.共享正在呈指数式增长的数据是我们必须要面对的一个重要挑战. 2.数据分析包括数据采集.数据存储.检查.清洗.分析.转换和建模等方法对数据进行处理的 ...
- Linux基础:sort命令总结
本文只总结一些常用的用法,更详细的说明见man sort和sort --help. sort命令 sort命令用于串联排序指定文件并将结果写到标准输出. sort可以指定按照何种排序规则进行排序,如按 ...