LucasColas / Leetcode-Solutions-Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Leetcode-Solutions-Python

Problem Topics Covered solution (idea)
344 - Reverse String string, 2 pointers Use 2 pointers and swap the values.
1721 - Swapping Nodes in a Linked List 2 pointers Use 3 pointers. Find kth node from right using pointer that points to the kth node from left and use a pointer which points to the head. Iterate until tail.next == None.
703 - Kth Largest Element in a Stream heap, loop Convert list to heap, delete every largest element to get an heap of length k. Every time we add values, we delete the larget element and return the smallest element.
682 - Baseball Game array Iterate through ops, check different cases. Return the sum of all the scores.
100 - Same Tree Tree Check if the two values are the same or not.
705 - Design HashSet HashSet, Set Use set ; add, discard and search elements in the set.
706 - Design HashMap array, index Use an array, the key serves as an index in the array.
844 - Backspace String Compare string, array, join Append to a list every char different from #, use join to build the new string.
1679 - Max Number of K-Sum Pairs Two pointers Sort the array.Two pointers. One starts from very begining & another from the end of the array.
191 - Number of 1 Bits loop Iterate until n = 0. Divide by 2 and use modulo 2.
703 - Kth Largest Element in a Stream Heap Use heap. Pop until the length of the heap is equal to k.
318 - Maximum Product of Word Lengths string, loop Compare each string with every other string of the list.
1480 - Running Sum of 1d Array for loop To alculate the i-th number : i-th value of nums + i-1-th value.
867 - Transpose Matrix loop, array New 2D array to contain the transpose of a Matrix. new_matrix(j)(i) = matrix(i)(j).
167 - Two Sum II - Input array is sorted Two pointers Pointer1 starts at 0, Pointer2 starts at the end of the array. If the sum is greater than target, we move Pointer2 to the left, otherwise we move Pointer1 to the right until the sum is equal to target.
1662 - Check If Two String Arrays are Equivalent strings Use join to concatenate every string of an array.
766 - Toeplitz Matrix Array Iterate through the 2D array. Check if matrix[i-1][j-1] != matrix[i][j].
2089 - Find Target Indices After Sorting Array Array, sort Iterate over the vector and compare each value with target.
151 - Reverse Words in a String String Split the string and convert it into a list, then reverse the list and transform the latter in a string.

About

License:MIT License


Languages

Language:Python 100.0%