leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 2a0bc686a8f5e5584637050f175832a7215d8c5f
parent 86cb2f9baa158a1f511a2697e38ef27afe49981f
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Fri, 21 Apr 2023 21:58:36 -0500

Completed jewels and stones set problem with dart

Diffstat:
Ajewels-and-stones/jewels-and-stones.dart | 20++++++++++++++++++++
1 file changed, 20 insertions(+), 0 deletions(-)

diff --git a/jewels-and-stones/jewels-and-stones.dart b/jewels-and-stones/jewels-and-stones.dart @@ -0,0 +1,20 @@ +//For each stone check if the given index is the same character as +//a jewel. If it is add one to the number of jewels returned. +//This algorithm is a O(n + m) time complexity where n is the length of the stones and m is the length of the jewels. +//Runtime: 249ms Beats: 83.33% +//Memory: 141MB Beats: 40.48% +class Solution { + int numJewelsInStones(String jewels, String stones) { + Set <String> vals = {}; + for(int i = 0 ; i < jewels.length ; ++i){ + vals.add(jewels[i]); + } + int return_val = 0; + for(int i = 0 ; i < stones.length ; ++i){ + if(jewels.contains(stones[i])){ + return_val += 1; + } + } + return return_val; + } +}