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就能找到.主要是 ...
随机推荐
- Spring MVC 复习
概念 三层架构 将整个业务应用划分为三层 表现层:用来和客户端进行数据交互,一般采用MVC设计模式 业务层:处理公司具体业务逻辑 持久层:用来操作数据库 MVC模型 Model View ...
- Linux环境:VMware下windows虚拟机与linux主机进行文件共享的方法
操作主要分两大步骤: 一.是对主机进行配置: 二.是在虚拟机上直接连接共享目录. 一.主机配置 1.打开VMware虚拟机,双击需要进行文件共享的虚拟机.如下图,双击CentOS 64位(以linux ...
- 使用 HttpWebRequest 类做 POST 请求没有应反
这几天给系统做第三方集成, 需要调用另一个软件的一个接口, 通过 HTTP 的方式调用,调用代码也挺简单的: string serviceUrl = string.Format("{0}/{ ...
- English--名词从句
English|名词从句 现在开始讲述关于名词从句的内容.从句大家都不陌生,但是学习了那么多年,什么是从句?接下来让我们一起来看看. 前言 目前所有的文章思想格式都是:知识+情感. 知识:对于所有的知 ...
- Vue相关知识点记录
1.安装 vue不支持ie8以下版本(无法模拟ECMAScript5特性),支持所有兼容ECMAScript5的浏览器. 浏览器安装Vue Devtools, 可以在更友好的界面中审查和调试Vue应用 ...
- 8 Traits of an Experienced Programmer that every beginner programmer should know
Referrence: http://whats-online.info/guides-and-info/36/Traits-of-Experienced-Programmer-that-every- ...
- Computer Networking: A Top Down Approach
目录 Chapter 1: Computer Networks and the Internet 1. What is the Internet? 2. The Network Edge 3. The ...
- Node.js 中 exports 和 module.exports 的区别
每一个模块中都有一个 module 对象, module 对象中有一个 exports 对象 我们可以把需要导出的成员都放到 module.exports 这个接口对象中,也就是 module.exp ...
- 聊聊webpack 4
前言 hello,小伙伴们,本篇仓库出至于我的GitHub仓库 web-study ,如果你觉得对你有帮助的话欢迎star,你们的点赞是我持续更新的动力 web-study webpack 打包工具 ...
- SpringBoot2.x应用启动、关闭shell脚本
本篇主要说明以下内容: 1.SpringBoot2.x应用启动.关闭的shell脚本 1 启动脚本 直接放到同jar包同一个目录下,如下: #!/usr/bin/env bash APPLICATIO ...