classSolution:defnumOfBurgers(self, tomatoSlices:int, cheeseSlices:int)-> List[int]:"""
假设制作的小皇堡为x, 制作的巨无霸汉堡为y
不难列出:
2x + 4y = tomatoSlices
x + y = cheeseSlices
化简后:
y = (tomatoSlices-2*cheeseSlices)/2
如果y能被整除,则证明不会剩下原料,否则,就会剩下,返回[]
"""
remainder =(tomatoSlices-2*cheeseSlices)%2# 求余数
total_jumbo =(tomatoSlices-2*cheeseSlices)//2
total_small =(4*cheeseSlices - tomatoSlices)//2ifnot remainder and total_jumbo >=0and total_small >=0:return[total_jumbo, total_small]return[]
题目2
题解2
# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = NoneclassSolution:defdeleteNode(self, node):"""
:type node: ListNode
:rtype: void Do not return anything, modify node in-place instead.
"""
node.val,node.next=node.next.val,node.next.next
题目3
题解3
classSolution:defjudgeCircle(self, moves:str)->bool:"""
判断moves中"U"和"D"、"L"和"R"的个数是否相等
"""
U = moves.count("U")
D = moves.count("D")
L = moves.count("L")
R = moves.count("R")if U == D and L == R:returnTruereturnFalse