• 题目描述

给定字符串J代表是珠宝的石头类型,而S代表你拥有的石头.S中的每个字符都是你拥有的一个石头. 你想知道你的石头有多少是珠宝.

J中的字母一定不同,JS中的字符都是字母。 字母区分大小写,因此"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. 珠宝和石头的更多相关文章

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

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

  2. 18.Jewels and Stones(珠宝和石头)

    Level:   Easy 题目描述: You're given strings J representing the types of stones that are jewels, and Sre ...

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

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

  4. 1038. Jewels And Stones

    描述 给定字符串J代表是珠宝的石头类型,而S代表你拥有的石头.S中的每个字符都是你拥有的一个石头. 你想知道你的石头有多少是珠宝. J中的字母一定不同,J和S中的字符都是字母. 字母区分大小写,因此& ...

  5. 771. Jewels and Stones珠宝数组和石头数组中的字母对应

    [抄题]: You're given strings J representing the types of stones that are jewels, and S representing th ...

  6. lintcode算法周竞赛

    ------------------------------------------------------------第七周:Follow up question 1,寻找峰值 寻找峰值 描述 笔记 ...

  7. [LintCode]——目录

    Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...

  8. Team Leader 你不再只是编码, 来炖一锅石头汤吧

    h3{ color: #000; padding: 5px; margin-bottom: 10px; font-weight: bolder; background-color: #ccc; } h ...

  9. (lintcode全部题目解答之)九章算法之算法班题目全解(附容易犯的错误)

    --------------------------------------------------------------- 本文使用方法:所有题目,只需要把标题输入lintcode就能找到.主要是 ...

随机推荐

  1. Schnorr签名介绍

    Schnorr签名介绍 来源 https://panzhibiao.com/2019/02/28/schnorr-sigature/ https://github.com/bitcoin/bitcoi ...

  2. altermanager使用报错

    报错如下: level=warn ts=2019-01-24T09:20:01.122920737Z caller=cluster.go:148 component=cluster err=" ...

  3. maven项目整合SSM配置log4j, 实现控制台打印SQL语句

    在原有项目正常启动的情况下, 实现在控制台打印mapper包下SQL语句. 1.在pom.xml配置文件中添加两个依赖(缺一不可) <!--日志包--> <dependency> ...

  4. Kubemetes

    将应用docker化,配合ETCD.kubernetes等工具在容器的层面上实现高可用和负载均衡 容器化部署 容器化部署应用具有灵活.高效的使用资源,容器可以包含其所需的全部文件,如同在虚拟机上部署应 ...

  5. 关于UDP协议

    UDP协议的特点. 1.UDP是一个无连接协议,传输数据之前接收端和发送端之间不建立连接. 想传输数据的时候就抓取数据扔出去,不监控是否被正确和全面的接受到. 2.因为不需要建立连接,也就不需要维护连 ...

  6. EntityFramework DBContext 类动态控制 数据库连接(支持Oracle,SQL server)

     public class ManagementDBContext : DbContext     {         public static string configString = Conf ...

  7. getsockopt套接口选项

    1. getsockopt int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen); i ...

  8. Java JDBC结果集的处理

    结果集指针的移动 while (resultSet.next()){ //...... } 指针最初指向第一条记录之前,next()是指向下一个位置,返回的是boolean值,true表示有内容(记录 ...

  9. mysql: show processlist 详解

    最近排查一些MySQL的问题,会经常用到 show processlist,所以在这里把这个命令总结一下,做个备忘,以备不时只需. show processlist 是显示用户正在运行的线程,需要注意 ...

  10. Golang: 读取文件并统计内容

    上次我们从命令行接收用户输入,并统计了每次输入内容出现的次数,今天对程序加以改造,使其能够读取文件内容,并统计每行文本出现的次数. 首先,我们把接收输入的逻辑封装成一个函数: // scan.go p ...