This repository contains Python solutions for various LeetCode problems. Below is a brief summary of the solved problems:
-
Two Sum
- Link to the problem
- Description: Given an array of integers and a target, return indices of two numbers that add up to the target.
- File: 1. Two Sum
-
Print in Order
- Link to the problem
- Description: Implement a mechanism to ensure that three methods are called in order:
first() -> second() -> third()
. - File: 1114. Print in Order
-
Roman to Integer
- Link to the problem
- Description: Convert a Roman numeral to an integer.
- File: 13. Roman to Integer
-
Longest Common Prefix
- Link to the problem
- Description: Find the longest common prefix string among an array of strings.
- File: 14. Longest Common Prefix
-
Add Two Numbers
- Link to the problem
- Description: Two linked lists represent non-negative integers. Return their sum as a linked list.
- File: 2. Add Two Numbers
-
Delete Node in a Linked List
- Link to the problem
- Description: Delete a node in a linked list given only access to that node.
- File: 237. Delete Node in a Linked List
-
Permutations
- Link to the problem
- Description: Return all possible permutations of a collection of distinct integers.
- File: 46. Permutations
-
Longest Palindromic Substring
- Link to the problem
- Description: Find the longest palindromic substring in a string.
- File: 5. Longest Palindromic Substring
-
Fibonacci Number
- Link to the problem
- Description: Calculate the Fibonacci number for a given index.
- File: 509. Fibonacci Number
-
Palindrome Number
- Link to the problem
- Description: Determine whether an integer is a palindrome.
- File: 9. Palindrome Number
-
Remove Duplicates from Sorted Array II
- Link to the problem
- Description: Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.
- File: 80. Remove Duplicates from Sorted Array II
-
Merge Sorted Array
- Link to the problem
- Description: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 in sorted order.
- File: 88. Merge Sorted Array
-
Rotate Array
- Link to the problem
- Description: Given an array
nums
, rotate the array to the right byk
steps, wherek
is non-negative. - File: 189. Rotate Array
-
Jump Game
- Link to the problem
- Description: Given an array of non-negative integers
nums
, determine if you can reach the last index. - File: 55. Jump Game
-
Jump Game II
- Link to the problem
- Description: Given an array of non-negative integers
nums
, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your goal is to reach the last index in the minimum number of jumps. - File: 45. Jump Game II
-
Best Time to Buy and Sell Stock II
- Link to the problem
- Description: Given an array
prices
representing the price of a stock on each day, find the maximum profit you can achieve by completing as many transactions as you like. - File: 122. Best Time to Buy and Sell Stock II
-
Insert Delete GetRandom O(1)
- Link to the problem
- Description: Design a data structure that supports all following operations in average O(1) time:
insert(val)
,remove(val)
, andgetRandom()
. - File: Insert Delete GetRandom O(1)
-
Gas Station
- Link to the problem
- Description: Given gas stations with gas amounts and travel costs, find the starting station index if you can travel the circuit once clockwise with an unlimited gas tank, else return -1.
- File: 134. Gas Station
-
Reverse Words in a String
- Link to the problem
- Description: Given an input string
s
, reverse the order of the words. - File: 151. Reverse Words in a String
-
Best Time to Buy and Sell Stock
- Link to the problem
- Description: Given an array
prices
, find the maximum profit by buying and selling stocks once. - File: 121. Best Time to Buy and Sell Stock
-
Candy
- Link to the problem
- Description: Distribute candy to children based on their ratings.
- File: 135. Candy
-
ZigZag Conversion
- Link to the problem
- Description: Convert the input string into a zigzag pattern and then read it row by row.
- File: 6. ZigZag Conversion
-
Minimum Length of String After Deleting Similar Ends
- Link to the problem
- Description: Remove matching characters from both ends of a string s until no identical ends remain.
- File: 1750. Minimum Length of String After Deleting Similar Ends
-
Minimum Length of String After Deleting Similar Ends
- Link to the problem
- Description: Find two numbers in a sorted array that add up to a target integer.
- File: 167. Two Sum II - Input Array Is Sorted