LeetCode
sunnylinner
宅
展开
-
7. Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to show spoilers. Have you thought about this? Here are some good questions to ask before coding.原创 2016-03-20 10:41:35 · 319 阅读 · 0 评论 -
18. 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: Elements原创 2016-04-13 16:57:44 · 386 阅读 · 0 评论 -
19. Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the l原创 2016-04-15 11:24:02 · 234 阅读 · 0 评论 -
20. Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all valid b原创 2016-04-15 12:21:08 · 239 阅读 · 0 评论 -
22. Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: "((()))", "(()())", "(())()", "()(())", "()()()"原创 2016-04-15 19:55:21 · 218 阅读 · 0 评论 -
21. Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. public class Solution{ public ListNode mergeTwoLists原创 2016-04-15 16:38:28 · 232 阅读 · 0 评论 -
23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. public class Solution { public ListNode mergeKLists(ListNode[] lists) { if (lists == null || list原创 2016-04-16 15:00:18 · 365 阅读 · 0 评论 -
24. Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. You m原创 2016-04-17 10:56:32 · 241 阅读 · 0 评论 -
25. Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.原创 2016-04-18 17:18:53 · 265 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with原创 2016-04-19 08:54:48 · 226 阅读 · 0 评论 -
27. Remove Element
Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. The原创 2016-04-20 11:42:56 · 388 阅读 · 0 评论 -
29. Divide Two Integers
Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. public class Solution { public int divide (int dividend, int divisor) { final i原创 2016-04-23 11:05:07 · 356 阅读 · 0 评论 -
28.Implement strStr()
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. public class Solution { public int strStr(String haystack, String n原创 2016-04-21 18:23:13 · 518 阅读 · 0 评论 -
30.Substring with Concatenation of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and原创 2016-08-30 17:14:50 · 348 阅读 · 0 评论 -
31. Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible原创 2016-08-31 10:41:31 · 240 阅读 · 0 评论 -
17. Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit string原创 2016-04-12 15:24:30 · 374 阅读 · 0 评论 -
16. 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly原创 2016-04-11 19:12:07 · 260 阅读 · 0 评论 -
6. ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I原创 2016-03-20 00:12:02 · 408 阅读 · 0 评论 -
2. Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2016-03-09 15:03:08 · 336 阅读 · 0 评论 -
1.Two Sum
Given an array of integers, return indices of the two numbers suchthat they add up to a specific target. You may assume that each input would have exactly onesolution. public int[] twoSum(int[]原创 2016-03-09 15:35:54 · 259 阅读 · 0 评论 -
5. Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. public class Solution {原创 2016-03-09 18:01:14 · 372 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For原创 2016-03-10 14:36:25 · 307 阅读 · 0 评论 -
9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, no原创 2016-04-03 22:26:32 · 337 阅读 · 0 评论 -
4. Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). public class Solution { pu原创 2016-03-12 21:27:05 · 439 阅读 · 0 评论 -
10. Regular Expression Matching
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire inp原创 2016-04-06 02:00:11 · 250 阅读 · 0 评论 -
8. String to Integer (atoi)
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input case原创 2016-04-06 02:11:29 · 256 阅读 · 0 评论 -
11. Container With Most Water
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原创 2016-04-07 22:13:45 · 237 阅读 · 0 评论 -
12. Integer to Roman
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. public class Solution { private static String M[] = {"","M","MM","MMM"}; private stati原创 2016-04-08 17:55:56 · 197 阅读 · 0 评论 -
13. Roman to Integer
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. public class Solution { public int romanToInt(String s) { if(s == null || s.length() ==原创 2016-04-09 23:39:35 · 376 阅读 · 0 评论 -
14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. public class Solution { public String longestCommonPrefix(String[] strs) { int len = strs.length; if(len ==原创 2016-04-10 02:42:05 · 244 阅读 · 0 评论 -
15. 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a,b,c) m原创 2016-04-10 14:48:26 · 248 阅读 · 0 评论 -
32. Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. For "(()", the longest valid parentheses substring is "()",原创 2016-08-31 23:32:58 · 247 阅读 · 0 评论