Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python leetcode

# Solution for Leetcode1: Two Sum problem
# Time complexity: O(n) and Space complexity: O(n)
# n is the size of the input list, namely nums

"""
Given an array of integers nums and an integer target, 
return indices of the two numbers such that they add up to target.
"""
class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        hashmap = {}
        for i in range(len(nums)):
            complement = target - nums[i]
            if complement in hashmap:
                return [i, hashmap[complement]]
            hashmap[nums[i]] = i
Comment

leetcode python

def merge(self, nums1, m, nums2, n):
        while m > 0 and n > 0:
            if nums1[m-1] >= nums2[n-1]:
                nums1[m+n-1] = nums1[m-1]
                m -= 1
            else:
                nums1[m+n-1] = nums2[n-1]
                n -= 1
        if n > 0:
            nums1[:n] = nums2[:n]
Comment

leetcode solutions python

Python solution for Leetcode
Python solution of problems from LeetCode.

https://github.com/Garvit244/Leetcode
Comment

PREVIOUS NEXT
Code Example
Python :: access class variable from another class python 
Python :: pandas series filter by index 
Python :: escape sequence in python 
Python :: not equal python 
Python :: how to find a square root of a number using python 
Python :: pandas df represent a long column name with short name 
Python :: python bytes 
Python :: format column from string to numeric in python 
Python :: create django project 
Python :: python open directory and read files 
Python :: decrypt vnc password 
Python :: pandas reset index from 0 
Python :: python new date 
Python :: dropna pandas 
Python :: python print emoji 
Python :: conda cassandra 
Python :: Python write value in next row of existing .text file 
Python :: getsizeof python 
Python :: string acharacters count in python without using len 
Python :: odoo order by xml rpc 
Python :: python list contain list 
Python :: how to search for a data in excel pandas 
Python :: Filter Pandas rows by specific string elements 
Python :: python find string count in str 
Python :: text animation python 
Python :: run a python script from another python script on a raspberry pi 
Python :: terminal output redirect to a file 
Python :: python txt to parquet 
Python :: python verify if string is a integer 
Python :: solidity compiler for python 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =