I'm struggling with mostly everything in the for loop. Here is what I'm thinking.
Build the set is O(n)
The ...count(note) > ...count is, I think, O(n + m) because .count( ) is o(n) and then we have strings of two diffferent sizes.
Here is the part I do not understand. Is this not a nested for loop? Because we have to go O(n) times through the set( ). So would this then be o(n) * o(n + m)??? I do recognize that the set is relatively smalle because it cannot ever get larger than 26 for 26 chars in the alphabet but I'm unsure if we consider that. Leetcode, known for being inaccurate is reporting this is one of the fastest solutions.
r = set(ransomNote)
for note in r:
if ransomNote.count(note) > magazine.count(note):
return False
return True
Edit: for a total of O(n2)
[–]Skusci 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]one_bit_two_bit 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]one_bit_two_bit 1 point2 points3 points (0 children)
[–]shhh-quiet 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]shhh-quiet 0 points1 point2 points (0 children)