
leetcode
文章平均质量分 71
ghoshorn
这个作者很懒,什么都没留下…
展开
-
leetcode 19 Remove Nth Node From End of List
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原创 2015-04-12 15:05:59 · 403 阅读 · 0 评论 -
leetcode 3 Longest Substring Without Repeating Characters
Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters原创 2015-03-18 15:29:27 · 333 阅读 · 0 评论 -
leetcode 1 Two Sum
Two SumGiven an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to th原创 2015-03-18 15:24:16 · 327 阅读 · 0 评论 -
leetcode 18 4Sum
4SumGiven 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:原创 2015-04-14 18:24:25 · 395 阅读 · 0 评论 -
leetcode 25 Reverse Nodes in k-Group
Reverse Nodes in k-GroupGiven 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 i原创 2015-04-14 16:32:37 · 356 阅读 · 0 评论 -
leetcode 24 Swap Nodes in Pairs
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 sho原创 2015-04-14 15:32:24 · 372 阅读 · 0 评论 -
leetcode 14 Longest Common Prefix
Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.需要注意的特殊情况:输入是个空列表import unittestclass Solution: # @return a string def l原创 2015-04-08 11:17:20 · 393 阅读 · 0 评论 -
leetcode 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 ca原创 2015-03-20 17:03:29 · 320 阅读 · 0 评论 -
leetcode 4 Median of Two Sorted Arrays
Median of Two Sorted ArraysThere are two sorted arrays A and B 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)).原创 2015-03-19 14:57:32 · 400 阅读 · 0 评论 -
leetcode 13 Roman to Integer
Roman to IntegerGiven a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.从字符串中每次处理一位,处理前需要先找到剩余串的枢纽(剩余串中最大的),以判断当前值在其左边还是右边,该相加还是相减。i原创 2015-04-08 10:57:06 · 372 阅读 · 0 评论 -
leetcode 9 Palindrome Number
Palindrome NumberDetermine 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 yo原创 2015-03-20 17:23:19 · 311 阅读 · 0 评论 -
leetcode 15 3Sum
3SumGiven 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 tr原创 2015-04-08 17:26:11 · 436 阅读 · 0 评论 -
leetcode 7 Reverse digits of an integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321class Solution: # @return an integer def reverse(self, x): tmp=abs(x) if tm原创 2015-03-20 16:38:57 · 363 阅读 · 0 评论 -
leetcode 11 Container With Most Water
Container With Most WaterGiven 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 lin原创 2015-04-07 17:42:27 · 309 阅读 · 0 评论 -
leetcode 5 Longest Palindromic Substring
Longest Palindromic SubstringGiven 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 palindrom原创 2015-03-19 18:03:14 · 307 阅读 · 0 评论 -
leetcode 10 Regular Expression Matching & 44 Wildcard Matching
leetcode中的两个 正则表达式匹配原创 2015-03-26 14:44:30 · 588 阅读 · 0 评论 -
leetcode 21 Merge Two Sorted Lists
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.# Definition for sin原创 2015-04-12 16:09:18 · 346 阅读 · 0 评论 -
leetcode 22 Generate Parentheses
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:"((()))", "(()原创 2015-04-12 16:45:12 · 354 阅读 · 0 评论 -
leetcode 23 Merge k Sorted Lists
Merge k Sorted ListsMerge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.可以通过leetcode 21的merge Two Lists来解决。如果从头到尾依此合并,会超时。改用分治法来调用。链表个数l>3时,原创 2015-04-12 17:09:48 · 426 阅读 · 0 评论 -
leetcode 16 3Sum Closest
3Sum ClosestGiven 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 inpu原创 2015-04-12 13:51:33 · 330 阅读 · 0 评论 -
leetcode 17 Letter Combinations of a Phone Number
Letter Combinations of a Phone NumberGiven a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone原创 2015-04-12 14:32:27 · 391 阅读 · 0 评论 -
leetcode 20 Valid Parentheses
Valid ParenthesesGiven a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()"原创 2015-04-12 15:53:18 · 347 阅读 · 0 评论 -
leetcode 26 Remove Duplicates from Sorted Array
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原创 2015-04-13 15:14:01 · 463 阅读 · 0 评论 -
leetcode 30 Substring with Concatenation of All Words
Substring with Concatenation of All WordsYou are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenat原创 2015-04-13 16:29:44 · 449 阅读 · 0 评论 -
leetcode 28 Implement strStr()
Implement strStr()Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.要注意特殊情况,比如strstr("","") 应该等于0 =_=class原创 2015-04-13 15:46:09 · 277 阅读 · 0 评论 -
leetcode 27 Remove Element
Remove Element Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave be原创 2015-04-13 15:23:05 · 367 阅读 · 0 评论 -
leetcode 29 Divide Two Integers
Divide Two Integers Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.class Solution1: # @return an integer def divi原创 2015-04-13 16:07:41 · 350 阅读 · 0 评论 -
leetcode 12 Integer to Roman
数字转换为罗马数字原创 2015-04-07 19:11:24 · 360 阅读 · 0 评论 -
leetcode 6 ZigZag Conversion
ZigZag ConversionThe 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)原创 2015-03-20 16:16:43 · 284 阅读 · 0 评论