python what is the difference between nums1=nums1[:m] and nums1[:]=nums1[:m]


  • 0
    R

    class Solution(object):
    def merge(self, nums1, m, nums2, n):
    """
    :type nums1: List[int]
    :type m: int
    :type nums2: List[int]
    :type n: int
    :rtype: void Do not return anything, modify nums1 in-place instead.
    """
    nums1=nums1[:m]
    nums2=nums2[:n]
    nums1=nums1+nums2
    nums1.sort()

    Input:
    [0]
    0
    [1]
    1
    Output:
    [0]
    Expected:
    [1]

    But, if i change
    from nums1=nums1[:m]
    to nums1[:]=nums1[:m]
    it works.
    anybody know the difference?
    thanks!!!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.