leetcode-4.11[1276. 不浪费原料的汉堡制作方案、237. 删除链表中的节点、657. 机器人能否返回原点](python解法)

题目1

在这里插入图片描述

题解1

class Solution:
    def numOfBurgers(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)//2
        if not remainder and total_jumbo >= 0 and 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 = None

class Solution:
    def deleteNode(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

class Solution:
    def judgeCircle(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:
            return True
        return False

附上题目链接

题目1链接
题目2链接
题目3链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值