class Solution(object):
def canConstruct(self, ransomNote, magazine):
"""
:type ransomNote: str
:type magazine: str
:rtype: bool
"""
for i in range(len(ransomNote)):
if ransomNote[i] in magazine:
magazine = magazine[:magazine.index(ransomNote[i])] + magazine[magazine.index(ransomNote[i]) + 1:]
continue
else:
return False
return True
Sol = Solution()
print Sol.canConstruct('aa','aab')
0,自己写的代码
1,题目要求:
2,用到的办法是直接对字符串进行切割的操作,以达到删除特定索引的字符的目的。