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就能找到.主要是 ...
随机推荐
- kaishi
https://zjc.wtc.edu.cn/zs/2019/0623/c2937a54869/page.htm https://zjc.wtc.edu.cn/zs/2019/0614/c593a54 ...
- Nginx深入详解之upstream分配方式
一.分配方式 Nginx的upstream支持5种分配方式,下面将会详细介绍,其中,前三种为Nginx原生支持的分配方式,后两种为第三方支持的分配方式: 1.轮询 轮询是upstream的默认分配方式 ...
- python的new与init
基于文章:Why is init() always called after new()? 特别说明: 这篇文章的灵感来源于stackoverflow的一个提问,准确说,我只是做了些知识梳理的工作,对 ...
- node.js中的fs.rename()方法
node.js 中的fs.rename()模块 var fs=require('fs');//node.js的核心模块 原生模块.修改文件名称,可更改文件的存放路径 方法说明 : 修改文件名称,可更改 ...
- map字典,储存cookie,切换账户,展示购物车不同商品
1:首页 1,静态html5+css做好基本样式 html5,css,jQery, sass 2,jsonp的方式src引入模拟的json数据//这里用的jsonp方式拿数据,详情有使用ajax 遍历 ...
- echarts设置横坐标的信息竖向排放
需要在xAxis 中添加 axisLabel , demo案例如下: 设置成每行两个文字竖向排放. xAxis : [ { type : 'category', data : this.xAxis, ...
- APP安全测试
app 常见风险 一. clinet端 1.反编译 2.签名破解 3.调试 4.导出组件 5.拒绝服务 6.输入记录 二.传输 1.信息泄露,未使用加密服务(ssl) 2.篡改 三.服务端 1.SQL ...
- 接口自动化--日志类封装(logging)
上篇随笔已经写到了读取Excel类的封装了,下面就写下日志类, 日志类在我们自动化的过程中是十分重要的,在我们的自动化程序出现异常的时候就可以打印日志 下面是我自己封装的日志类 import logg ...
- django项目用higcharts统计最近七天文章点击量。
下载higcharts插件放在static文件夹下 前端引入 <script src="/static/highcharts/highcharts.js"></s ...
- 201671010404+陈润菊 实验十四 团队项目评审课程&学习总结
个人学习总结博客 这个作业属于哪个课程 软件工程任教教师 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p/11093584.html 作业学习目标 (1 ...