leetcode
文章平均质量分 67
大三狗
这个作者很懒,什么都没留下…
展开
-
LeetCode 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原创 2015-04-21 19:08:32 · 3136 阅读 · 0 评论 -
LeetCode 19 Remove Nth Node From End of List 移除倒数第N个节点
题目: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-04 15:37:00 · 2622 阅读 · 1 评论 -
LeetCode 18 4sum 找出4个数,使得他们的和等于target
题目: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:原创 2015-05-04 15:05:40 · 2567 阅读 · 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.翻译:把2个有序链表连接,返回一个新链表思路:很简单,就是遍历每个节点,小的话添加在原创 2015-05-05 10:21:26 · 2400 阅读 · 0 评论 -
LeetCode22 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-05 13:24:39 · 2801 阅读 · 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原创 2015-05-05 10:12:34 · 2611 阅读 · 0 评论 -
LeetCode24 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 s原创 2015-05-06 13:55:14 · 2560 阅读 · 3 评论 -
LeetCode23 Merge k Sorted Lists 把K个有序链表连接成一个
题目:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.翻译:把K个有序的链表合成一个,返回。思路:这道题和昨天的Merge 2 Lists有些类似。但是k不确定,如果用每个都去遍历的话,肯定是不会通过的。So、可以想到的是归原创 2015-05-06 11:17:26 · 2531 阅读 · 0 评论 -
LeetCode 25 Reverse Nodes in k-Group K个一组反转节点
题目: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原创 2015-05-06 15:02:57 · 2371 阅读 · 0 评论 -
LeetCode 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 p原创 2015-05-07 12:26:40 · 1684 阅读 · 1 评论 -
LeetCode 27 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 len原创 2015-05-07 12:39:27 · 1741 阅读 · 0 评论 -
LeetCode 16 3Sum Closest 找出最接近指定target的三个数的和
题目: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 hav原创 2015-05-04 09:26:28 · 2319 阅读 · 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原创 2015-05-04 10:38:46 · 3185 阅读 · 0 评论 -
LeetCode13 Roman to Integer 罗马转为数字
题目:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.翻译:把罗马转为数字思路:如果是单纯的一个罗马字母比较好处理,但是对于4,9这样的,应该看它下一个字符代表的数字是不是比他大,要是大的话减去当前的字符原创 2015-04-22 13:55:31 · 2010 阅读 · 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,原创 2015-04-22 11:11:28 · 2283 阅读 · 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,5,10原创 2015-04-22 12:56:24 · 1741 阅读 · 0 评论 -
LeetCode 15 3Sum 找出数组里面3个数的和等于指定值。
题目: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 tripl原创 2015-04-23 13:17:25 · 4086 阅读 · 0 评论 -
LeetCode 9 Palindrome Number 回文数字
题目:Determine whether an integer is a palindrome. Do this without extra space.翻译:判断一个数字是否是回文数,不要额外空间。解题思路:因为数字既然传过去了,就不会有越界的问题。每次只需要取最前面和最后面的那一位数字进行比较,相同则继续,不同则返回、首先要获取数字的位数,假设数字是12344321,一共有8位。原创 2015-04-20 14:55:27 · 3346 阅读 · 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 i原创 2015-04-20 12:55:57 · 3103 阅读 · 0 评论 -
Leetcode 7 Reverse Integer 反转数字
题目:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321翻译就是把一个数字反过来输出。解题思路:这道题目看起来比较简单。无非就是一个数字取个位,作为另一个高位。无非是在10的运算。代码1: public static int rever原创 2015-04-20 10:28:58 · 6027 阅读 · 0 评论 -
LeetCode:Longest Palindromic Substring 最长回文子串
忽然找到一位关于此题详细介绍的大牛文章。转载之,以后常回顾一下。http://www.cnblogs.com/tenosdoit/p/3675788.html表示没学过动态规划,闲下来时候研究研究。算法4挺别出心裁,值得学习!题目链接Given a string S, find the longest palindromic substring in转载 2015-04-17 10:46:57 · 2249 阅读 · 0 评论 -
leetcode 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 NA P原创 2015-04-17 13:18:20 · 3280 阅读 · 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.翻译:找到字符串的子串位置,并返回。如果没有则返回-1思路:通过最简单的BF遍历,如果不符合则指向下一个字符,原创 2015-05-07 16:54:38 · 1459 阅读 · 1 评论