Skip to content

Andrade-Diego/leetCodeSolns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Solutions to LeetCode Problems

Versions

Language Version
C++ C++14
Python Python3
JavaScript Node.js v15.3.0

twoSum

Iterate through each element in list. Use a hash table to store difference between the current number and the target and map it to the current index. If an observed value is in the hash table, use the index of that observed value and the index it's mapped to in the table to generate the result.

  • C++
    • Runtime: 4 ms, faster than 99.85% of C++ submissions.
    • Memory Usage: 9.4 MB, less than 76.56% of C++ submissions.
  • Python
    • Runtime: 48 ms, faster than 72.41% of Python submissions.
    • Memory Usage: 14.5 MB, less than 75.5% of Python submissions.

Container With Most Water

Use a pointer to the left of the list and the right of the list. Use the smaller of the two heights and the difference in the left and right pointer's indices to calculate the area. Keep value for area if it's larger than the previous largest. Iterate the pointer that has a smaller height at each step; reducing the width with the same height will exclusively produce smaller areas, so we don't want to keep that height for future consideration.

  • C++
    • Runtime: 32 ms, faster than 94.11% of C++ submissions.
    • Memory Usage: 18 MB, less than 93.7% of C++ submissions.
  • Python
    • Runtime: 156 ms, faster than 91.07% of Python submissions.
    • Memory Usage: 16.5 MB, less than 36.33% of Python submissions.

Minimum Number of Steps to Make Two Strings Anagram

  • Python Used Counter() from the Collections library to count instances of characters in the string. Then iterating through the Counter object containing the two strings' difference allowed me to find the steps needed to make the second string an anagram.
    • Runtime: 252 ms, faster than 41.93% of Python submissions.
    • Memory Usage: 14.8 MB, less than 72.24% of Python submissions.

Delete Nodes and Return Forest

  • Python Recursive solution using preorder tree traversal
    • Runtime: 60 ms, faster than 94.37% of Python submissions.
    • Memory Usage: 15 MB, less than 14.74% of Python submissions.

Median of Two Sorted Arrays

  • Python Used a pointer for each list, the smaller value goes into the new "merge" list. In order to achieve O(log(n+m)) time, the entirety of each list is not used, only the first half + 1 of the total number of values needs to be used.
    • Runtime: 88 ms, faster than 79.72% of Python submissions.
    • Memory Usage: 14.4 MB, less than 62.34% of Python submissions.

Distribute Candies to People

  • Python Used numpy for a mathy solution. Using the property that the sum of all natural numbers up to n is equal to \[n(n+1)/2\], to help find the answer.
    • Runtime: 91 ms, faster than 5.42% of Python submissions.
    • Memory Usage: 31.6 MB, less than 13.86% of Python submissions.

Valid Parentheses

  • Python Use a stack to keep track of the most recently opened parentheses type, when the program comes across a close parentheses of the right type, it pops it off the stack. If the stack is empty at the end of the string, it is a valid string.
    • Runtime: 28 ms, faster than 82.64% of Python submissions.
    • Memory Usage: 14.1 MB, less than 94.19% of Python submissions.

Remove Duplicates From Sorted Array

  • Python A fast pointer and a slow pointer are used to iterate through the list, the slow pointer stops at the first instance of each number, the fast pointer traces through the whole array and removes the element at its index if it is the same as the element at the slow pointer
    • Runtime: 96 ms, faster than 31.36% of Python submissions.
    • Memory Usage: 15.8 MB, less than 71.87% of Python submissions.

Validate Binary Search Tree

  • Python Use DFS and recursion to iterate through tree, keep track of the lowerLimit and upperLimit for what a node value can contain.
    • Runtime: 36 ms, faster than 96.93% of Python submissions.
    • Memory Usage: 16.3 MB, less than 85.93% of Python submissions.

Search a 2D Matrix II

  • JavaScript Use binary search to check each row for the target. Runtime then is O(m*logn)
    • Runtime: 2920 ms, faster than 13.9% of Python submissions.
    • Memory Usage: 41.9 MB, less than 50.8% of Python submissions.

Transpose Matrix

  • Python Used a list comprehension for a quick, one-line solution.
    • Runtime: 60 ms, faster than 98.88% of Python submissions.
    • Memory Usage: 14.8 MB, less than 73.25% of Python submissions.

Binary Tree Level Order Traversal

  • Python Recursive solution for level order tree traversal.
    • Runtime: 24 ms, faster than 98.92% of Python submissions.
    • Memory Usage: 15.3 MB, less than 6.84% of Python submissions.

Single Number

  • Python

    • Runtime: 132 ms, faster than 65.57% of Python submissions.
    • Memory Usage: 16.5 MB, less than 81.41% of Python submissions.

Remove Element

  • Python

    • Runtime: 24 ms, faster than 98.44% of Python submissions.
    • Memory Usage: 14 MB, less than 98.6% of Python submissions.

Merge Two Sorted Lists

  • Python

    • Runtime: 32 ms, faster than 91.62% of Python submissions.
    • Memory Usage: 14.1 MB, less than 95.46% of Python submissions.

Length of Last Word

  • Python Solution from scratch, not using rstrip() or split().
    • Runtime: 30 ms, faster than 81.62% of Python submissions.
    • Memory Usage: 14.2 MB, less than 66.42% of Python submissions.

Plus One

  • Python

    • Runtime: 28 ms, faster than 88.89% of Python submissions.
    • Memory Usage: 14.2 MB, less than 75.49% of Python submissions.

Two Sum ii - Input array is sorted

  • Python

    • Runtime: 56 ms, faster than 95.62% of Python submissions.
    • Memory Usage: 14.7 MB, less than 32.18% of Python submissions.

Add Binary

  • Python

    • Runtime: 24 ms, faster than 97.93% of Python submissions.
    • Memory Usage: 14.7 MB, less than 82.35% of Python submissions.

Range Addition II

  • Python

    • Runtime: 64 ms, faster than 90.61% of Python submissions.
    • Memory Usage: 16.1 MB, less than 87.85% of Python submissions.

Flood Fill

  • Python

    • Runtime: 72 ms, faster than 84.47% of Python submissions.
    • Memory Usage: 14.4 MB, less than 76.65% of Python submissions.

Intersection Of Two Linked Lists

  • Python

    • Runtime: 148 ms, faster than 97.70% of Python submissions.
    • Memory Usage: 31.9 MB, less than 5.56% of Python submissions.

Sort Array by Parity

  • Python Used deque from collections for faster prepending to list.
    • Runtime: 68 ms, faster than 98.81% of Python submissions.
    • Memory Usage: 15 MB, less than 82.26% of Python submissions.

Self Dividing Numbers

  • Python
    • Runtime: 40 ms, faster than 94.19% of Python submissions.
    • Memory Usage: 14.1 MB, less than 84.06% of Python submissions.

Valid Palindrome

  • Python Pythonic two line solution.
    • Runtime: 40 ms, faster than 89.60% of Python submissions.
    • Memory Usage: 20 MB, less than 8.16% of Python submissions.

Min Cost Climbing Stairs

  • Python Dynamic programming solution.
    • Runtime: 52 ms, faster than 91.16% of Python submissions.
    • Memory Usage: 14.3 MB, less than 90.81% of Python submissions.

Find the Duplicate Number

  • JavaScript
    • Runtime: 72 ms, faster than 98.03% of JavaScript submissions.
    • Memory Usage: 40.2 MB, less than 39.28% of JavaScript submissions.

Reverse Words in a String

  • JavaScript
    • Runtime: 72 ms, faster than 97.1% of JavaScript submissions.
    • Memory Usage: 40.4 MB, less than 58.30% of JavaScript submissions.

    Reverse Words in a String

MajorityElement

  • JavaScript
    • Runtime: 80 ms, faster than 91.22% of JavaScript submissions.
    • Memory Usage: 40.5 MB, less than 96.16% of JavaScript submissions.

Find Minimum in Rotated Sorted Array

  • JavaScript Binary search solution
    • Runtime: 76 ms, faster than 85.52% of JavaScript submissions.
    • Memory Usage: 38.6 MB, less than 62.61% of JavaScript submissions.

Find Peak Element

  • JavaScript
    • Runtime: 72 ms, faster than 93.99% of JavaScript submissions.
    • Memory Usage: 38.5 MB, less than 84.37% of JavaScript submissions.

Permutations

  • JavaScript
    • Runtime: 84 ms, faster than 98.90% of JavaScript submissions.
    • Memory Usage: 41.7 MB, less than 53.25% of JavaScript submissions.

Remove Nth Node From End of List

  • JavaScript Two Pointer technique solution.
    • Runtime: 76 ms, faster than 95.57% of JavaScript submissions.
    • Memory Usage: 40 MB, less than 78.79% of JavaScript submissions.

Reverse Linked List

  • JavaScript
    • Runtime: 80 ms, faster than 87.35% of JavaScript submissions.
    • Memory Usage: 40.2 MB, less than 86.19% of JavaScript submissions.

Remove Linked List Elements

  • JavaScript
    • Runtime: 88 ms, faster than 97.03% of JavaScript submissions.
    • Memory Usage: 43.1 MB, less than 89.92% of JavaScript submissions.

Binary Tree Preorder Traversal

  • Python
    • Runtime: 24 ms, faster than 96.07% of Python submissions.
    • Memory Usage: 14.1 MB, less than 77.94% of Python submissions.

Binary Tree Inorder Traversal

  • Python
    • Runtime: 24 ms, faster than 96.24% of Python submissions.
    • Memory Usage: 14.2 MB, less than 78% of Python submissions.

Binary Tree Postorder Traversal

  • Python
    • Runtime: 28 ms, faster than 86.23% of Python submissions.
    • Memory Usage: 14 MB, less than 91.99% of Python submissions.

About

just doing some puzzles :)

Resources

Stars

Watchers

Forks

Contributors