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就能找到.主要是 ...
随机推荐
- jQuery---bootstrap的下载使用,栅格(12个格子),轮播图,矢量图字体图标,进度条,选项卡,标签,表达校验
jQuery---bootstrap的下载使用,栅格(12个格子),轮播图,矢量图字体图标,进度条,选项卡,标签,表达校验 一丶bootstrap的使用 下载资源文件: bootstrap官网 导入 ...
- 玩转zynq7010+ FPGA点亮三色灯
前期主要以开发Z-TURN的PL部分为主,以期望了解该芯片的逻辑架构和系统总线,以及所有外设,后面在开始PS部分的开发,闲话少说,先看整个7z010的系统框图,所有开发目前基于ISE14.6来设置, ...
- Java 之 LinkedList 集合
一.LinkedList 概述 java.util.LinkedList 集合数据存储的结构是链表结构. 特点:增删快,查询慢 LinkedList 是一个双向链表,如下图 注意:该集合实现不是同步 ...
- 英语hecatolite月长石hecatolite月光石
月长石英文名字为hecatolite即月光石.当白色的光照到宝石上因宝石内特殊的结构而产生干涉颜色,在宝石表面可见到白至淡蓝色的闪光,犹如朦胧月光.这是由于正长石出溶有钠长石,钠长石在正长石晶体内定向 ...
- Python paramiko安装报错
报错:CryptographyDeprecationWarning 代码引用: import paramiko client = paramiko.SSHClient() client.connect ...
- Ettercap 详细参数
Ettercap最初设计为交换网上的sniffer,但是随着发展,它获得了越来越多的功能,成为一款有效的.灵活的中介攻击工具.它支持主动及被动的协议解析并包含了许多网络和主机特性(如OS指纹等)分析. ...
- The 2019 Asia Yinchuan First Round Online Programming F. Moving On
t题目链接:https://nanti.jisuanke.com/t/41290 思路:题目意思很容易想到floyd,但是由于危险度的限制,我们该怎么跑floyd呢. 一开始理解错题目了,以为u-&g ...
- PAT 甲级 1025.PAT Ranking C++/Java
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Z ...
- 配置nginx的systemctl命令
启动nginx的命令为 /usr/local/nginx/sbin/nginx 停止nginx的命令为 /usr/local/nginx/sbin/nginx -s stop 重启ng ...
- redis 哨兵集群原理及部署
复制粘贴自: https://www.cnblogs.com/kevingrace/p/9004460.html 请点击此链接查看原文. 仅供本人学习参考, 如有侵权, 请联系删除, 多谢! Redi ...