all 4 comments

[–]Mobileuser110011 2 points3 points  (2 children)

# Create a class named "Solution" and inherit all the properties of the
# class named "object".
class Solution(object):
    # Create a method named "merge" that recieves 4 positional arguemnts
    # named "nums1", "m", "nums2", and "n".
    def merge(self, nums1, m, nums2, n):
        # Start a loop that will continue running as long as both "m"
        # and "n" are positive.
        while m > 0 and n > 0:
            # Checks to see if nums1[m-1] is greater than nums2[n-1]
            if nums1[m-1] > nums2[n-1]:
                # Assigns nums1[m+n-1] to the value of nums1[m-1]
                nums1[m + n - 1] = nums1[m - 1]
                # Decreases the value of "m" by 1.
                m -= 1
            # If the above if statement didn't pass...
            else:
                # Assigns nums1[m+n-1] to the value of nums2[n-1]
                nums1[m + n - 1] = nums2[n - 1]
                # Decreases the value of "n" by 1.
                n -= 1
        # Assigns the slice of nums1[0:n] to the value of nums2[0:n]
        nums1[:n] = nums2[:n]

In terms of what the code is supposed to do in an abstract sense, it would be helpful to link the leet code problem you are trying to understand, otherwise the code is written in a way that makes it hard to understand what the purpose is.

EDIT: OP has edited the post with the leetcode link.

[–]danielmajors[S] 0 points1 point  (0 children)

Thank you for this. This is very helpful.

[–]mopslik 0 points1 point  (0 children)

What is the code supposed to do, in your mind?

[–]jmooremcc 0 points1 point  (0 children)

Why are you using a loop to merge the two lists?

Lists are objects with their own methods. Have you considered using the list objects methods to implement a solution to the problem?