
leetcode
文章平均质量分 69
qibobo
这个作者很懒,什么都没留下…
展开
-
[leetcode]3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "原创 2016-10-09 00:03:03 · 254 阅读 · 0 评论 -
[leetcode]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原创 2016-10-19 00:03:11 · 261 阅读 · 0 评论 -
[leetcode]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 va原创 2016-10-19 20:22:25 · 382 阅读 · 0 评论 -
[leetcode]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.直接上代码了。java/** * Definition for singly-linked list原创 2016-10-19 20:39:45 · 251 阅读 · 0 评论 -
[leetcode] 1. Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example:Given nums =原创 2016-10-07 17:30:22 · 355 阅读 · 0 评论 -
[leetcode] 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-10-07 21:34:40 · 266 阅读 · 0 评论 -
[leetcode]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-11-01 18:30:32 · 280 阅读 · 0 评论 -
[leetcode]23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Leetcode 21题是合并两个链表。合并K个链表的方法就是2的进一步。有两种方法:1 归并法。即每次链表数组中相邻的两个链表合并,结果为一个新的链表数组,重复之前的流程知道数组中只有一个元原创 2016-11-01 18:38:53 · 201 阅读 · 0 评论 -
[leetcode]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. Y原创 2016-11-01 18:43:27 · 338 阅读 · 0 评论 -
[leetcode]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-11-01 18:48:09 · 313 阅读 · 0 评论 -
[leetcode]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: The solution原创 2016-10-18 23:25:16 · 288 阅读 · 0 评论 -
[leetcode]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:Di原创 2016-10-18 23:20:01 · 268 阅读 · 0 评论 -
[leetcode]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 exact原创 2016-10-17 22:34:23 · 256 阅读 · 0 评论 -
[leetcode]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)).Example 1:nums1 =原创 2016-10-09 21:31:38 · 232 阅读 · 0 评论 -
[leetcode]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.本题是求一个字符串的最长的回文子串。原创 2016-10-10 22:09:20 · 226 阅读 · 0 评论 -
[leetcode]7. Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before c原创 2016-10-10 22:47:49 · 269 阅读 · 0 评论 -
[leetcode] 9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of convertin原创 2016-10-13 23:07:45 · 278 阅读 · 0 评论 -
[leetcode]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). Fin原创 2016-10-13 23:21:08 · 263 阅读 · 0 评论 -
[leetcode]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.这道题基本没什么算法上的难点,就是需要知道罗马字母和整数的对应关系就行了。1~9: {"I", "II", "III", "IV", "V", "VI", "V原创 2016-10-15 18:13:54 · 282 阅读 · 0 评论 -
[leetcode]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.这道题和12题正好相反,但是要比12题难一点。最重要的还是要熟悉对应表。1~9: {"I", "II", "III", "IV", "V", "VI", "VI原创 2016-10-15 18:21:39 · 251 阅读 · 0 评论 -
[leetcode]14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.比较简单,直接上代码。java代码public class Solution { public String longestCommonPrefix(String[] strs) { if(s原创 2016-10-15 21:49:09 · 250 阅读 · 0 评论 -
[leetcode]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: The solution set must not contain原创 2016-10-17 22:19:46 · 252 阅读 · 0 评论 -
[leetcode]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.java代码public class Solution { public int strStr(String原创 2016-12-08 18:11:11 · 363 阅读 · 0 评论