
leetcode
all-is-well
这个作者很懒,什么都没留下…
展开
-
Leetcode - 19. Remove Nth Node from end of List
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原创 2016-05-10 16:36:02 · 403 阅读 · 0 评论 -
Leetcode-10. Regular Expression Matching
题目介绍 ‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should b原创 2016-06-06 21:23:56 · 416 阅读 · 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). Find原创 2016-06-12 19:45:12 · 373 阅读 · 0 评论 -
Leetcode-44. Wildcard Matching
题目介绍Implement wildcard pattern matching with support for ‘?’ and ‘*’. ‘?’ Matches any single character. ‘*’ Matches any sequence of characters (including the empty sequence). The matching sho原创 2016-06-12 17:13:36 · 335 阅读 · 0 评论 -
Leetcode-69 Sqrt(x)
题目介绍 Implement int sqrt(int x). Compute and return the square root of x.解决方法int sqrt(int x) { if (0 == x) return 0; int left = 1, right = x, ans; while (left <= right) {原创 2016-06-05 17:33:00 · 484 阅读 · 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: Elements in a triplet (a原创 2016-05-23 00:39:50 · 404 阅读 · 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 al原创 2016-05-22 20:19:47 · 372 阅读 · 0 评论 -
Leetcode-349 Intersection of Two Arrays
题目介绍 Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. Note: Each element in the result must be unique原创 2016-05-22 20:11:12 · 458 阅读 · 0 评论 -
Leetcode-Power of 2,3,4
问题描述 Given an integer, write a function to determine if it is a power of x.(在这里,我们考虑x=2,3,4三种情况) Follow up: Could you do it without using any loop / recursion?一般解法 以x==3为例 bool isPowerOfT原创 2016-06-03 18:03:38 · 474 阅读 · 0 评论 -
Leetcode - 38. Count and Say
38. Count and Say题目简介 The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, … 1 is read off as “one 1” or 11. 11 is read off as “two 1s”原创 2016-05-06 22:14:18 · 1218 阅读 · 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.Simple solution(超时)思路原创 2016-05-06 20:40:54 · 447 阅读 · 0 评论 -
Leetcode - 4. Median of Two Sorted Arrays
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原创 2016-05-06 19:42:20 · 581 阅读 · 0 评论 -
Leetcode - 14. Longest Common Prefix
题目介绍 Write a function to find the longest common prefix string amongst an array of strings.思路以第一个字符串作为参照,与其他字符串比较对应位置的字符是否相等;在遍历首字符串的过程中,遍历比较vector。若都相等,将该字符添加在结果中,然后继续; 反之跳出循环;注意:若vector为空,则返回”“原创 2016-05-29 11:25:46 · 358 阅读 · 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. 方法思路: 1. 对每个字符进行数字的映射,这里存储在数组中; 2. 遍历字符串,针对IV,VI等这类数字,使用两个指针表示,若发现前者小于后者,结果su原创 2016-05-26 16:43:59 · 363 阅读 · 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. 解决方法思路: 空间换时间 string intToRoman(int num) { string M[4] ={"","M","MM",原创 2016-05-26 16:33:38 · 335 阅读 · 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.Tags : Linked List方法一class Solution {public: Li原创 2016-05-10 16:33:22 · 444 阅读 · 0 评论 -
Leetcode - 88. Merge Sorted Array
题目简介 Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to原创 2016-05-10 16:34:35 · 389 阅读 · 0 评论 -
Leetcode-70. Climbing Stairs
题目介绍 You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?解法思路: a. n==0, f(n) =原创 2016-06-06 23:34:09 · 338 阅读 · 0 评论