转阴后开始补作业
1、1754. 构造字典序最大的合并字符串
leetcode 1754题
class Solution:
def largestMerge(self, word1: str, word2: str) -> str:
def isBigger(i,j):
for k in range(len(word1)-i):
if j+k>=len(word2):
return True
if word1[i+k]>word2[j+k]:
return True
elif word1[i+k]<word2[j+k]:
return False
return False
i,j=0,0
ret = ""
while i<len(word1) and j<len(word2):
if isBigger(i,j):
ret += word1[i]
i += 1
else:
ret += word2[j]
j += 1
if i<len(word1):ret+=word1[i:]
if j<len(word2):ret += word2[j:]
return ret