Skip to content

vg42/java-leetcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java LeetCode

Java solutions for LeetCode problems.

# Title Solution Test cases Time Space Description Difficulty
0001 Two Sum Two sum solution Two sum tests O(n) O(n) n = nums.length Easy
0002 Add Two Numbers Add Two Numbers solution Add Two Numbers tests O(n) O(n) n = max(len(l1), len(l2)), where len(l) - number elements in the list l Medium
0003 Longest Substring Without Repeating Characters Longest Substring Without Repeating Characters solution Longest Substring Without Repeating Characters tests O(n) O(k) n = s.length(); k - number of possible characters Medium
0004 Median of Two Sorted Arrays Median of Two Sorted Arrays solution Median of Two Sorted Arrays tests O(log(min(l1, l2))) O(1) l1 = nums1.length, l2 = nums2.length Hard
0005 Longest Palindromic Substring Longest Palindromic Substring solution Longest Palindromic Substring tests O(n^2) O(1) n = s.length(); worst case - all chars are same Medium
0006 ZigZag Conversion ZigZag Conversion solution ZigZag Conversion tests O(n) O(n) n = s.length() Medium
0007 Reverse Integer Reverse Integer solution Reverse Integer tests O(log10(x)) O(1) Easy
0010 Regular Expression Matching Regular Expression Matching solution Regular Expression Matching tests O(n * m) O(n * m) n=s.length, m=p.length Hard
0015 3Sum 3Sum solution 3Sum tests O(n^2) O(1) n=nums.length Medium
0020 Valid Parentheses Valid Parentheses solution Valid Parentheses tests O(n) O(n) n=s.length() Easy
0021 Merge Two Sorted Lists Merge Two Sorted Lists solution Merge Two Sorted Lists tests O(n) O(1) n - number of all ListNode in the lists Easy
0023 Merge k Sorted Lists Merge k Sorted Lists solution Merge k Sorted Lists tests O(n * log(k)) O(1) n - number of all ListNode in the lists, k=lists.length() Hard
0033 Search in Rotated Sorted Array Search in Rotated Sorted Array solution Search in Rotated Sorted Array tests O(log(n)) O(1) n=nums.length Hard
0050 Pow(x, n) Pow(x, n) solution Pow(x, n) tests O(log(n)) O(log(n)) - Easy
0056 Merge Intervals Merge Intervals solution Merge Intervals tests O(n * log(n)) O(n) n=interval.length() Medium
0069 Sqrt(x) Sqrt(x) solution Sqrt(x) tests O(log(x)) O(1) - Medium
0076 Minimum Window Substring Minimum Window Substring solution Minimum Window Substring tests O(n) O(n) n=s.length()+t.length() Hard
0088 Merge Sorted Array Merge Sorted Array solution Merge Sorted Array tests O(n + m) O(1) - Medium
0100 Same Tree Same Tree solution Same Tree tests O(min(n,m)) O(min(n,m)) n, m - numbers elements in the trees p and q Easy
0121 Best Time to Buy and Sell Stock Best Time to Buy and Sell Stock solution Best Time to Buy and Sell Stock tests O(n) O(1) n=prices.length Easy
0146 LRU Cache LRU Cache solution LRU Cache tests O(1) O(capacity) Hard
0200 Number of Islands Number of Islands solution Number of Islands tests O(n * m) O(n * m) n * m - number of cells in the grid Medium
0206 Reverse Linked List Reverse Linked List solution Reverse Linked List tests O(n) O(1) - iterative, O(n) - recursive n - number elements in the list Easy
0238 Product of Array Except Self Product of Array Except Self solution Product of Array Except Self tests O(n) O(n) n=nums.length Medium
0253 Meeting Rooms II Meeting Rooms II solution Meeting Rooms II tests O(n * log(n)) O(n) n=intervals.length Medium
0273 Integer to English Words Integer to English Words solution Integer to English Words tests O(n) O(1) n - number of digits in num Hard
0283 Move Zeroes Move Zeroes solution Move Zeroes tests O(n) O(1) n=nums.length Easy
0297 Serialize and Deserialize Binary Tree Serialize and Deserialize Binary Tree solution Serialize and Deserialize Binary Tree tests O(n) O(n) n - number of nodes in the tree Hard
0301 Remove Invalid Parentheses Remove Invalid Parentheses solution Remove Invalid Parentheses tests O(2^n) O(n^2) - without result list n=s.length() Hard
0325 Maximum Size Subarray Sum Equals k Maximum Size Subarray Sum Equals k solution Maximum Size Subarray Sum Equals k tests O(n) O(n) n=nums.length Medium
0461 Hamming Distance Hamming Distance solution Hamming Distance tests O(n) O(n) n - number of bits in (x or y) Easy
0973 K Closest Points to Origin K Closest Points to Origin solution K Closest Points to Origin tests O(n) O(1) n=points.length Medium
1012 Complement of Base 10 Integer Complement of Base 10 Integer solution Complement of Base 10 Integer tests O(n) O(n) n - number of bits in N Easy
1013 Pairs of Songs With Total Durations Divisible by 60 Pairs of Songs With Total Durations Divisible by 60 solution Pairs of Songs With Total Durations Divisible by 60 tests O(n) O(1) n=time.length Easy
1014 Capacity To Ship Packages Within D Days Capacity To Ship Packages Within D Days solution Capacity To Ship Packages Within D Days tests O(n * log(sum * (D - 1) / D) O(1) n=weights.length, sum=sum(weights) Medium

About

Java solutions for LeetCode problems

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages