1, use Python Implementation stack
class Stack(object): def __init__(self): self.items = [] def isEmpty(self):
return len(self.items) == 0 def push(self, item): self.items.append(item) def
pop(self): return self.items.pop() def peek(self): return self.items[-1] def
size(self): return len(self.items)
2, Detection of unordered words
If one string just rearranges the characters of another string , So this string is another out of order word , such as heart and earth
Counting method : Determine whether each character in two strings appears the same number of times
def solution(s1, s2): c1 = [0] * 26 c2 = [0] * 26 for i in range(len(s1)): pos
= ord(s1[i]) - ord('a') c1[pos] += 1 for i in range(len(s2)): pos = ord(s2[i])
- ord('a') c2[pos] += 1 stillok = True for i in range(26): if c1[i] != c2[i]:
stillok = False break return stillok
Technology