
LeetCode
文章平均质量分 71
bigface1234fdfg
贴在地上过日子,有个好处就是,摔也摔不到哪儿去。
展开
-
Two Sum
Two Sum1. Problem DescriptionGiven 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, where index1 must be less tha原创 2015-01-13 09:35:08 · 439 阅读 · 0 评论 -
Divide Two Integers ——解题报告
【题目】Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT. 【分析】 基本思想:任何数都可以分成二进制的幂的线性表示。 例子:以87除4举例, (4 * 2 = 8) => (原创 2015-05-15 13:23:12 · 686 阅读 · 0 评论 -
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)). 解法1: 直原创 2015-05-06 10:13:41 · 1189 阅读 · 0 评论 -
Integer to Roman ——解题报告
【题目】 Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999. 分析: 首先,我们需要知道罗马数字的表示方法,可参考链接:http://blog.youkuaiyun.com/ljiabin/article原创 2015-05-06 19:30:16 · 633 阅读 · 0 评论 -
Roman to Integer ——解题报告
【题目】 Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999. 【分析】 这个和上篇博文中把数字转换为罗马数字正好相反,逻辑过程有点儿复杂。 其实解法来源于对罗马数字(字符串)的观察,原创 2015-05-06 20:17:46 · 622 阅读 · 0 评论 -
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 co原创 2015-05-06 10:47:16 · 944 阅读 · 0 评论 -
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原创 2015-05-06 17:48:26 · 599 阅读 · 0 评论 -
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 (原创 2015-05-07 10:01:46 · 863 阅读 · 0 评论 -
Longest Common Prefix ——解题报告
【题目】 Write a function to find the longest common prefix string amongst an array of strings. 【分析】 公共前缀指的是所有字符串的前缀都相同。显然,这个最长公共前缀的长度不会超过所有字符串中最短的那个。 我们先求得最短串长minLen,然后遍历所有字符串中的前原创 2015-05-07 08:08:42 · 1133 阅读 · 0 评论 -
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 ha原创 2015-05-07 10:36:15 · 761 阅读 · 0 评论 -
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原创 2015-05-08 09:47:32 · 701 阅读 · 0 评论 -
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原创 2015-05-08 10:22:37 · 678 阅读 · 0 评论 -
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 wordsexactly原创 2015-05-21 21:44:53 · 2096 阅读 · 0 评论 -
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 constan原创 2015-05-12 08:12:38 · 791 阅读 · 0 评论 -
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 beyond the new le原创 2015-05-12 13:39:43 · 788 阅读 · 0 评论 -
Add Two Numbers
Add Two NumbersYou 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原创 2015-01-13 15:22:59 · 455 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
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 let原创 2015-01-13 17:06:16 · 485 阅读 · 0 评论 -
ZigZag Conversion
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 le原创 2015-01-19 16:25:55 · 632 阅读 · 0 评论 -
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-01-21 07:39:36 · 568 阅读 · 0 评论 -
Reverse Integer
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 que原创 2015-01-20 10:14:04 · 649 阅读 · 0 评论 -
String to Integer (atoi)
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原创 2015-01-20 22:55:50 · 456 阅读 · 0 评论 -
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.原创 2015-05-08 08:33:59 · 2452 阅读 · 0 评论 -
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. 【分析】 不要忘记先判断两个链表是否有空链表。其余的使用递归和非递归原创 2015-05-08 13:01:33 · 1059 阅读 · 0 评论 -
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-05-09 09:07:59 · 861 阅读 · 0 评论 -
Merge k Sorted Lists ——待解决TLE
【题目】Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 【分析】 思路基于两个有序链表合并。只不过每次都需要遍历选出K个链表中最小的那个数。 【代码】 下面的代码始终LTE,原因是一个很原创 2015-05-09 11:16:31 · 507 阅读 · 0 评论 -
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 remai原创 2015-05-12 09:38:00 · 885 阅读 · 0 评论 -
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原创 2015-05-12 10:31:09 · 751 阅读 · 0 评论 -
LeetCode: 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 input st原创 2015-10-03 11:11:30 · 1167 阅读 · 0 评论