Skip to content

hemant0011/LeetCode-Solutions

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

140 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeetCode Solutions

Find video link at my YouTube channel
Or from the Sheet 1 of this Google Sheet

Languages Used - C++, Java, Python3

# Title Solution Code Time Space Difficulty Tags Video
0001 2 Sum problem Check all the combinations by looping Map, if it’s complement (target - element) and exists then return the indices of the current element and the complement. C++ Java O(n) O(1) Easy Hash Table Heap 📺
0021 Merge Two Sorted Lists Algo The strategy here uses a temporary dummy node as the start of the result list. The pointer Tail always points to the last node in the result list, so appending new nodes is easy. The dummy node gives the tail something to point to initially when the result list is empty. C++ O(m+n) O(1) Easy Linked List 📺
0026 Remove Duplicates from Sorted Array Algo check and compare all the elments if equal then delete Java O(n) O(1) Easy Array 📺
0027 Remove Element Two pointers for counting valid nos and swapping Java Python O(n) O(1) Easy Array Two Pointers 📺
0045 Jump Game II newEnd = max(newEnd, i+nums[i]) C++ O(n) O(1) Hard Array Greedy 📺
0053 Maximum Subarray Parse array and save the best solution at each step Java O(n) O(1) Easy Array Dynamic Programming
0055 Jump Game Iterate from last index and check if we can reach there from current index or not Python O(n) O(1) Medium Array Greedy 📺
0062 Unique Paths (Total no of unique paths in m x n matrix) As the first element in each row will always be 1, so maintaining one row is enough to reach bottom-right corner of the grid Java O(n) O(1) Medium Array Dynamic Programming
0070 Climbing Stairs steps[n]=steps[n-1]+steps[n-2]. C++ Python O(n) O(1) Easy Dynamic Programming 📺
0072 Edit Distance minDis(i,j)=min(minDis(i-1,j),minDis(i,j-1),minDis(i-1,j-1))+1; Java O(m*n) O(m*n) Hard String Dynamic programming
0073 Set Matrix Zeroes Use the first cell of every row and column as a flag. This flag would determine whether a row or column has been set to zero. C++ Python O(m*n) O(1) Medium Array 📺
0075 Sort an array of 0’s 1’s 2’s without using extra space or sorting algo the logic is to count total number of 0's, 1's and 2's int the list and starting from beginning first append total 0's then total 1's and then 2's Python O(n) O(1) Medium Array 📺
0100 Same Tree Check isSame(node.left) and isSame(root.right) Java O(n) O(h) Easy Tree Depth-first-Search 📺
0100 Same Tree Check isSame(node.left) and isSame(root.right) Java Python O(n) O(h) Easy Tree Depth-first-Search 📺
0101 Symmetric Tree Check if left.left==right.right and left.right==right.left Java O(n) O(h) Easy Tree Depth-first-Search Breadth-first-Search 📺
0104 Maximum Depth of Binary Tree Depth = 1 + Max(depth of left, depth of right) Java O(n) O(h) Easy Tree Depth-first-Search 📺
0121 Best time to buy and sell stock Minimize Cost price and Maximise Profit Java O(n) O(1) Easy Array Dynamic Programming 📺
0136 Single Number Algo ^ is the XOR operator. Let's assume we have an integer 'a'. So, a^a = 0 and a^0 = a Java O(n) O(1) Easy Bit manipulation 📺
0142 Linked List Cycle II Floyd’s Cycle detection algorithm Java O(n) O(1) Medium Linked List Two pointers
0200 Number of islands Merging adjacent lands, and the merging is done recursively Java O(n∗m) O(1) Medium Depth-First Search Breadth-First Search 📺
0268 Missing Number Assuming that XOR is a constant-time operation, this algorithm does constant work on nn iterations, so the runtime is overall linear C++ Java O(n) O(1) Easy Array Math BitManipulation
0283 Move Zeroes Two pointers for counting valid nos and swapping Java O(n) O(1) Easy Array Two Pointers 📺
0287 Find duplicate in array of N+1 numbers Find the cycle using slow and fast pointer Java O(n) O(1) Medium Array Two Pointers
0451 Sort Characters By Frequency LeetCode Github Java Python O(n) O(n) Medium Hash Table Heap
0509 Fibonacci Number Storing the value of two previous number and updating them Java O(n) O(1) Easy Array 📺
0647 Palindromic Substrings Extend from center, 2 function call for odd and even palindromes Java O(n^2) O(1) Medium String Dynamic Programming 📺
0695 Max Area of Island Apply DFS on the Gird by exploring every square connected to it 4-directionally, total number of squares explored will be the area of that connected shape. C++ O(R∗C) O(R∗C) Medium Depth-First-Search
0876 Middle of the Linked List Find the length of given linked list and then traverse from root till one less than half of linked list length and print the next node to current node Java O(n) O(1) Easy Linked List
0983 Minimum Cost For Tickets Here dp(i) is the cost to travel from day days[i] to the end of the plan. if days[j] < days[i] + 1 then j1=j. if days[j] < days[i] + 7 then j=j7. if days[j] < days[i] + 30 then j=j30 . dp(i)=min(dp(j1)+costs[0],dp(j7)+costs[1],dp(j30)+costs[2]) Java O(n) O(n) Medium Dynamic Programming 📺
1347 Minimum Number of Steps to Make Two Strings Anagram Add 1 for char in s and remove 1 for char in t Java O(n+m) O(1) Medium Hash Table Heap 📺
1352 Product of the Last K Numbers Add new element to list by multiplying it with previous number and return arr[n-1]/arr[n-k-1] Python O(1) O(1) Medium Array Design 📺

Format

0000 Ques name Algo Java O() O() Easy Category 📺
0000 Ques name Algo Java O() O() Easy Category 📺

Made with Python Made with Java Made with C++

Built with love

About

:octocat: (Daily Update) Java / Python Solutions of LeetCode Problems

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Java 64.8%
  • Python 21.1%
  • C++ 14.1%