2021-01-28

237、删除链表中的节点

# 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.val

        node.next = node.next.next

238、除自身以外数组的乘积

class Solution:

    def productExceptSelf(self, nums: List[int]) -> List[int]:

        products = [1]

        for i in range(1,len(nums)):

            products.append(nums[i-1]*products[-1])

            right_product = 1

        for i in range(len(nums)-1,-1,-1):

            products[i] *= right_product

            right_product *= nums[i]

        return products

292、Nim游戏

class Solution:

    def canWinNim(self, n: int) -> bool:

        m=n

        m=str(m)

        m=m[-2:]

        m=int(m)

        return (m!=0)and(m!=4)and(m!=8)and(m!=12)and(m!=16)and(m!=20)and(m!=24)and(m!=28)and(m!=32)and(m!=36)and(m!=40)and(m!=44)and(m!=48)and(m!=52)and(m!=56)and(m!=60)and(m!=64)and(m!=68)and(m!=72)and(m!=76)and(m!=80)and(m!=84)and(m!=88)and(m!=92)and(m!=96)

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 16、最接近的三数之和 classSolution: defthreeSumClosest(self,nums:L...
    wu_liao阅读 113评论 0 0
  • 两数相加 #Definitionforsingly-linkedlist. #classListNode: #de...
    wu_liao阅读 116评论 0 0
  • 215、数组中的第k个最大元素 classSolution: deffindKthLargest(self,num...
    wu_liao阅读 152评论 0 0
  • 23、合并K个升序链表 #Definitionforsingly-linkedlist. #classListNo...
    wu_liao阅读 110评论 0 0
  • 1、217. 存在重复元素[https://leetcode-cn.com/problems/contains-d...
    是黄小胖呀阅读 242评论 0 0