DEV Community

Discussion on: Algorithms Problem Solving: Ransom Note

Collapse
 
jingxue profile image
Jing Xue

Another solution:

    def can_construct(ransom_note, magazine):
        for c in ransom_note:
            prev_len = len(magazine)
            magazine = magazine.replace(c, '', 1)
            if len(magazine) == prev_len:
                return False
        return True
Collapse
 
teekay profile image
TK

Great, Jing!

This was very similar with my first solution. But I wanted to try a different solution without using the replace method. Just to challenge me.