Skip to content

Instantly share code, notes, and snippets.

@anujose1989
Created November 14, 2018 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anujose1989/ce510811a130f0721bb80684e536a436 to your computer and use it in GitHub Desktop.
Save anujose1989/ce510811a130f0721bb80684e536a436 to your computer and use it in GitHub Desktop.
Jewels And Stones
- (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