[抄题]:

You're given strings J representing the types of stones that are jewels, and S representing the stones you have.  Each character in Sis a type of stone you have.  You want to know how many of the stones you have are also jewels.

The letters in J are guaranteed distinct, and all characters in J and S are letters. Letters are case sensitive, so "a" is considered a different type of stone from "A".

Example 1:

Input: J = "aA", S = "aAAbbbb"
Output: 3

Example 2:

Input: J = "z", S = "ZZ"
Output: 0

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

[一句话思路]:

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

toCharArray(无参)可以用来打散字符串,很好用

[复杂度]:Time complexity: O(n) Space complexity: O(n)

[英文数据结构或算法,为什么不用别的数据结构或算法]:

hashset可以不用指定存储类型, 配合count就能统计数量了

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

[代码风格] :

class Solution {
public int numJewelsInStones(String J, String S) {
//cc
if (J.length() == 0 || S.length() == 0) {
return 0;
} //ini set, res
Set set = new HashSet();
int res = 0; //for loop,count
for (char j : J.toCharArray()) {
set.add(j);
}
for (char s : S.toCharArray()) {
if (set.contains(s)) res++;
} //return res
return res;
}
}

771. Jewels and Stones珠宝数组和石头数组中的字母对应的更多相关文章

  1. Leetcode#771.Jewels and Stones(宝石与石头)

    题目描述 给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石. J 中的字母不重复,J 和 S中的所有字 ...

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

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

  3. 【Leetcode_easy】771. Jewels and Stones

    problem 771. Jewels and Stones solution1: class Solution { public: int numJewelsInStones(string J, s ...

  4. 771. Jewels and Stones - LeetCode

    Question 771. Jewels and Stones Solution 题目大意:两个字符串J和S,其中J中每个字符不同,求S中包含有J中字符的个数,重复的也算 思路:Set记录字符串J中的 ...

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

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

  6. LeetCode --> 771. Jewels and Stones

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

  7. LeetCode 771. Jewels and Stones (宝石与石头)

    题目标签:Hash Table 这一题很简单,题目给了两个string:J 和 S. 只要把J 里面的 char 放入HashSet,再遍历S找出有多少个石头是宝石. Java Solution: R ...

  8. 【LeetCode】771. Jewels and Stones 解题报告

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 数组count 字典Counter 日期 题目地址 ...

  9. letCode(771 Jewels and Stones )

    问题描述: You're given strings J representing the types of stones that are jewels, and S representing th ...

随机推荐

  1. s3cmd 安装使用指南

    https://wangyan.org/blog/s3cmd-how-to-use.html s3cmd 安装使用指南 s3cmd 是一款 Amazon S3 命令行工具.它不仅能上传.下载.同步,还 ...

  2. KVO与KVC的使用(转)

    转自http://www.cnblogs.com/mybkn/archive/2013/05/29/3104166.html KVO: 在看KVO之前,有必要先了解下KVC,即,Key-Value C ...

  3. How to install php 7.x on CentOS 7

    Step 1: Setup the Webtatic YUM repo Precompiled PHP 7.x binaries are available for CentOS 7 from the ...

  4. IDEA Tomcat服务器 更新.jsp时,页面刷新无法同步修改

    这是因为在配置服务时没有配置好: on frame deactivation部分

  5. 学习动态性能表(21)v$lincense

    学习动态性能表 第20篇--v$lincense  2007.6.15 本节主要参数: SESSION_MAX:实例允许的并发最大session数量 SESSION_WARNING:当前实例警告的并发 ...

  6. 学习动态性能表(15)--v$rollstat

    学习动态性能表 第15篇--V$ROLLSTAT  2007.6.12 本视图自启动即保持并记录各回滚段统计项.在学习本视图之前,我们先来了解一下回滚段(rollback segment)的相关概念: ...

  7. untra edit 自动补全

    选择“高级-配置-编辑器-自动完成”,勾选“自动显示‘自动完成’对话框”,并在其中定义好“当输入x个字符”时,自动补全.

  8. BZOJ3489:A simple rmq problem

    浅谈\(K-D\) \(Tree\):https://www.cnblogs.com/AKMer/p/10387266.html 题目传送门:https://lydsy.com/JudgeOnline ...

  9. Azure VNet介绍

    Azure VNet的介绍 VNet是Azure云中逻辑隔离的虚拟网络.它包含两个含义: Azure的用户可以在VNet中创建自己的各种资源,感觉想自己的数据中心中一样; 在一个VNet中创建的资源和 ...

  10. 通过Azure File Service搭建基于iscsi的共享盘

    在Azure上目前已经有基于Samba协议的共享存储了. 但目前在Azure上,还不能把Disk作为共享盘.而在实际的应用部署中,共享盘是做集群的重要组件之一.比如仲裁盘.Shared Disk等. ...