新人求加米,加米不会消耗您的大米
第四题思路
将array全部转化为string,使用trie树记录下第一个array的所有数字
遍历第二个array,在字典中找prefix最大长度,时间复杂度为O(N*log(MAX_Number))class TrieNode:
def __init__(self, char):
self.char = char
self.is_end = False
self.counter = 0
self.children = {}
class Trie(object):
def __init__(self):
self.root = TrieNode("")
def insert(self, word):
node = self.root
for char in word:
if char in node.children:
list.append(matrix[i][y])
for i in range(len(matrix[0])):
if i != y:
list.append(matrix[x][i])
if checkList(list):
ans += 1
return ans
print(solution([[2,3]]))
print(solution([[1,2],[2,1]]))
print(solution([[1,1,1,1],[2,3,1,1],[1,1,1,0],[1,4,1,1]])) |