【Leetcode】Jewels and Stones
Jewels and Stones
Description
You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is 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
Note:
- S and J will consist of letters and have length at most 50.
- The characters in J are distinct.
Discuss
比较简单的题目,直接遍历就可以了。
Code
class Solution {
public int numJewelsInStones(String J, String S) {
int count = 0;
for (int i = 0; i < S.length(); i++) {
char aa = S.charAt(i);
for (int j = 0; j < J.length(); j++) {
char bb = J.charAt(j);
if (aa == bb) { count++; }
}
}
return count;
}
}
【Leetcode】Jewels and Stones的更多相关文章
- 【LeetCode】Jewels and Stones(宝石与石头)
这道题是LeetCode里的第771道题. 题目要求: 给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝 ...
- 【LeetCode】1033. Moving Stones Until Consecutive 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 脑筋急转弯 日期 题目地址:https://leet ...
- 【LeetCode】947. Most Stones Removed with Same Row or Column 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 并查集 日期 题目地址:https://leetco ...
- 【leetcode】1033. Moving Stones Until Consecutive
题目如下: Three stones are on a number line at positions a, b, and c. Each turn, you pick up a stone at ...
- 【leetcode】947. Most Stones Removed with Same Row or Column
题目如下: On a 2D plane, we place stones at some integer coordinate points. Each coordinate point may h ...
- 【LeetCode】哈希表 hash_table(共88题)
[1]Two Sum (2018年11月9日,k-sum专题,算法群衍生题) 给了一个数组 nums, 和一个 target 数字,要求返回一个下标的 pair, 使得这两个元素相加等于 target ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【Leetcode】Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
随机推荐
- 【Leetcode】【Easy】Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- 团队第三次scrum
长大一条龙之课表查询 一.设计概要 本次内容主要是实现了长大一条龙系统的课表查询功能,我们的这个项目严格遵守MVC架构,采用前后端分离的策略.我们将课表查询分为二层,DAO层:负责与数据进行交互,读写 ...
- 转 tcp协议里rst字段讲解
TCP协议的原理来谈谈rst复位攻击 http://russelltao.iteye.com/blog/1405349 几种TCP连接中出现RST的情况 https://blog.csdn.net/c ...
- Android(java)学习笔记47:通过反射获得构造方法并且使用
1. 获取字节码文件对象: Class c = Class.forName("cn.itcast_01.Person"); 2. 获取构造方法 ...
- BZOJ4566:[HAOI2016]找相同字符(SAM)
Description 给定两个字符串,求出在两个字符串中各取出一个子串使得这两个子串相同的方案数.两个方案不同当且仅当这两 个子串中有一个位置不同. Input 两行,两个字符串s1,s2,长度分别 ...
- 【[SDOI2008]洞穴勘测】
题目 由于始终保证连通性于是我们可以用\(LCT\)来维护这个森林 三个操作分别是\(link,cut,findroot\) 代码 #include<iostream> #include& ...
- L1 loss L2 loss
https://www.letslearnai.com/2018/03/10/what-are-l1-and-l2-loss-functions.html http://rishy.github.io ...
- Docker 常用指令
1.检查内核版本,必须是3.10及以上uname ‐r2.安装dockeryum install docker3.输入y确认安装4.启动docker[root@localhost ~]# system ...
- com.microsoft.sqlserver.jdbc.SQLServerException: Socket closed 或者 该连接已关闭
com.microsoft.sqlserver.jdbc.SQLServerException: Socket closed 或者 该连接已关闭 解决方案: DBUtil公共方法如下: package ...
- 解决:fontawesome-webfont.woff2?v=4.6.3 404 (Not Found)
用Bootstrap里面的字体,你项目中会报一个错,一个字体找不到,但我们的项目中却是存在这个字体的. 解决方法: 修改我们的Web.Config文件