Jewels and Stones - Leetcode 771 - Hashmaps & Sets (Python)

preview_player
Показать описание


Please check my playlists for free DSA problem solutions:

My Favorite Courses:

Data Structures & Algorithms:

Python:

Web Dev / Full Stack:

Cloud Development:

Game Development:

SQL & Data Science:

Machine Learning & AI:
Рекомендации по теме
Комментарии
Автор

Master Data Structures & Algorithms For FREE at AlgoMap.io!

GregHogg
Автор

Wow. First time I've seen something leetcode says is "easy" that I also thought was easy.

jdratlif
Автор

Bro, frl, cause of your videos, im studying a lot with a dream of one day be a software enginner, bought today the book grooking algorithms, im reading and doing your algomap. U r great, thank u!

pedroaugustopereira
Автор

Is this any good?:
from collections import Counter

def solution(jewels: str, stones: str) -> int:
counter = Counter(stones)
count = 0

for j in jewels:
count += counter[j]
return count

БайМаринМилионера
Автор

def numJewelsInStones(self, jewels, stones):
jules = set(jewels)
return sum(1 for stone in stones if stone in jules)

timkvernen
Автор

why use set? the contrains said the jewels are unique, doesnt need to do set ...

zodman
Автор

Why not using Counter?

from collections import Counter

def num_jewels_in_stones(jewels: str, stones: str):
stone_counter = Counter(stones)
return sum(stone_counter[jewel] for jewel in jewels)

jojojux
welcome to shbcf.ru