Created
November 14, 2018 00:36
-
-
Save anujose1989/ce510811a130f0721bb80684e536a436 to your computer and use it in GitHub Desktop.
Jewels And Stones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSInteger) jewelCountFromStone : (NSString*) stone : (NSString*) jewel | |
{ | |
NSInteger count = 0; | |
NSMutableDictionary *hashmap = [[NSMutableDictionary alloc]initWithCapacity:jewel.length]; | |
for ( NSInteger i = 0; i< jewel.length; i++) | |
{ | |
[hashmap setValue:[NSNumber numberWithInteger:1] forKey: [jewel substringWithRange:NSMakeRange(i,1)]]; | |
} | |
for ( NSInteger i = 0 ; i <stone.length ; i++) | |
{ | |
if ([hashmap valueForKey:[stone substringWithRange:(NSMakeRange (i,1))]]) | |
{ | |
count ++; | |
} | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment