DEV Community

Discussion on: Algorithms Problem Solving: Ransom Note

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
teekay profile image
TK Author

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.