
LeetCode
文章平均质量分 79
UndefinedZ01
这个作者很懒,什么都没留下…
展开
-
算法导论第二章POJ水题
第二章介绍了插入排序和归并排序,于是想到POJ上弄几道水题练下。排序的水题果断都好水,归并没有用哨兵,而是直接使用了2.3-2习题的方式,插入排序在查找位置的时候用的是2.3-6习题提到的二分查找。不过虽然是水题,但我是菜鸟水平,所以当看到高手用48K和0MS解决掉这些题后,真心觉得自己弱爆了。 水题号:2388; 归并:2388Ac原创 2012-08-01 14:39:02 · 903 阅读 · 0 评论 -
[LeetCode]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:"((()))", "(()())", "(())()", "(原创 2014-01-02 11:40:54 · 1036 阅读 · 0 评论 -
[LeetCode]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,原创 2013-12-03 10:19:28 · 1243 阅读 · 0 评论 -
[LeetCode]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:Dig原创 2013-11-27 22:10:35 · 972 阅读 · 0 评论 -
[LeetCode]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 linei is at (i, ai) and (i原创 2013-11-14 21:27:01 · 886 阅读 · 0 评论 -
[LeetCode]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 NA原创 2013-11-04 11:46:29 · 19237 阅读 · 2 评论 -
[LeetCode]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 h原创 2013-11-25 12:39:43 · 1012 阅读 · 0 评论 -
[LeetCode]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原创 2013-11-24 11:20:37 · 8073 阅读 · 0 评论 -
[LeetCode]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.也就是传说中的求最长回文子原创 2013-11-22 11:30:42 · 2224 阅读 · 0 评论 -
[LeetCode]Longest Common Prefix
题目要求如下:Write a function to find the longest common prefix string amongst an array of strings.找出所有字符串的最长公共前缀。这道题很简单,但需要注意减少比较字符的操作次数。思路是这样的:2个字符串的最长公共前缀,其长度肯定不会超过最短的字符串的长度,设最短的字符串长度为n,那么只要比较这2个原创 2013-11-22 12:37:41 · 22560 阅读 · 1 评论 -
[LeetCode]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原创 2013-11-03 11:15:31 · 992 阅读 · 0 评论 -
[LeetCode]Median of Two Sorted Arrays
题目要求:There 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)).如果使用像归并排序那样的归并方式,从头遍历A和B,比较A原创 2013-11-09 12:10:28 · 1193 阅读 · 0 评论 -
[LeetCode]Reverse Integer
题目要求:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Have you thought about this?Here are some good questions to ask before coding. Bonus points for原创 2013-11-13 21:34:43 · 13299 阅读 · 10 评论 -
[LeetCode]String to Integer (atoi)
题目要求:mplement 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 inpu原创 2013-11-13 21:45:36 · 5822 阅读 · 2 评论 -
[LeetCode]Two Sum
题目要求:Given 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 the target,原创 2013-11-01 20:48:37 · 2338 阅读 · 4 评论 -
[LeetCode]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原创 2013-11-01 22:23:21 · 17746 阅读 · 3 评论 -
[LeetCode]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 strin原创 2013-11-13 21:55:16 · 934 阅读 · 0 评论 -
[LeetCode]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 "()[]{}"原创 2013-12-28 11:45:34 · 9200 阅读 · 2 评论