[LeetCode&Python] Problem 771: Jewels and Stones

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

Note:

  • S and J will consist of letters and have length at most 50.
  • The characters in J are distinct.
class Solution:
    def numJewelsInStones(self, J, S):
        """
        :type J: str
        :type S: str
        :rtype: int
        """

        return len([elem for elem in S if elem in J])

  

原文地址:https://www.cnblogs.com/chiyeung/p/9650663.html

时间: 2024-08-30 10:10:09

[LeetCode&Python] Problem 771: Jewels and Stones的相关文章

Leetcode #771. Jewels and Stones

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

【博客搬家旧文】leetcode 771. Jewels and Stones

今天开通了博客园 ,之前的博客就不用了.之后再陆陆续续把之前的博文重新放到这里来.有标题这个tag的都是搬运的旧博客的文章.希望在这里是个新的开始,嘻嘻. import java.util.Scanner; class Solution { public static int numJewelsInStones(String J, String S) { int count=0; for(int i=0; i<J.length(); i++){ for(int j=0; j<S.length(

771. Jewels and Stones 珠宝和石头

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

771. Jewels and Stones - Easy

You're given strings J representing the types of stones that are jewels, and Srepresenting 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

letCode(771 Jewels and Stones )

问题描述: 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

[LeetCode&amp;Python] Problem 905: Sort Array By Parity

Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A. You may return any answer array that satisfies this condition. Example 1: Input: [3,1,2,4] Output: [2,4,3,1] T

[LeetCode&amp;Python] Problem 806. Number of Lines To Write String

We are to write the letters of a given string S, from left to right into lines. Each line has maximum width 100 units, and if writing a letter would cause the width of the line to exceed 100 units, it is written on the next line. We are given an arra

[LeetCode&amp;Python] Problem 811. Subdomain Visit Count

A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com", and at the lowest level, "discuss.leetcode.com". When we visit

[LeetCode&amp;Python] Problem 682. Baseball Game

You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 following types: Integer (one round's score): Directly represents the number of points you get in this round. "+" (one round's score): Represents