第一题
照题目叙述去写
Python Code:
class Solution:
def getSmallestString(self, s: str) -> str:
s = list(s)
for i in range(1,len(s)):
if int(s[i]) < int(s[i-1]) and (int(s[i]) % 2) == (int(s[i-1]) %
2):
s[i-1] , s[i] = s[i], s[i-1]
break
return "".join(s)
第二题:
照题目叙述去写
Python Code:
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def modifiedList(self, nums: List[int], head: Optional[ListNode]) ->
Optional[ListNode]:
nums = set(nums)
tmp = ListNode()
tmp.next = head
pre = tmp
cur = head
while cur:
if cur.val in nums:
pre.next = cur.next
else:
pre = cur
cur = cur.next
return tmp.next
第三题
我感觉是贪婪 但我想不到怎处理
总不可能直接模拟吧
放弃