Leetcode Diary

19. Remove Nth Node From End of List

Leetcode Diary

Given a linked list, remove the n-th node from the end of list and return its head. Example: Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the ...

18. 4Sum

Leetcode Diary

Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum ...

17. Letter Combinations of a Phone Number

Leetcode Diary

Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons...

16. 3Sum Closest

Leetcode Diary

Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input ...

15. 3Sum

Leetcode Diary

Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: The solution set mus...

14. Longest Common Prefix

Leetcode Diary

Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". Example 1: Input: ["flower","flow","flight"]...

13. Roman to Integer

Leetcode Diary

Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. Examples: Input: "III" Output: 3 Input: "IV" Output: 4 Input: "IX" Output: 9 Inp...

12. Integer to Roman

Leetcode Diary

Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. Examples: Input: 9 Output: "IX" Input: 58 Output: "LVIII" Explanation: L = 50, V = ...

11. Container With Most Water

Leetcode Diary

Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find...

10. Regular Expression Matching

Leetcode Diary

Given an input string (s) and a pattern (p), implement regular expression matching with support for . and *. . Matches any single character. * Matches zero or more of the preceding element. ...