
难
文章平均质量分 76
KiraYin--
这个作者很懒,什么都没留下…
展开
-
[LeetCode] Implement strStr()
Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.1. 暴力比较,过慢,无法通过大数据集合class Solution {public: char *strStr(char *haysta原创 2013-06-10 10:12:34 · 790 阅读 · 0 评论 -
[LeetCode] Largest Rectangle in Histogram
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width o原创 2013-09-20 10:20:06 · 776 阅读 · 0 评论 -
[LeetCode] Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combina原创 2013-09-22 23:52:06 · 942 阅读 · 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)).参考:http://fisherlei.blogspot.co原创 2013-09-25 23:23:18 · 971 阅读 · 0 评论 -
[LeetCode] Palindrom Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Return原创 2013-10-18 04:35:25 · 659 阅读 · 0 评论 -
[LeetCode] Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non原创 2013-10-24 11:03:05 · 646 阅读 · 0 评论 -
[LeetCode] Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.原创 2013-10-19 00:58:18 · 715 阅读 · 0 评论 -
[LeetCode] Populating Next RIght Pointer in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant extr原创 2013-10-19 04:35:14 · 624 阅读 · 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原创 2013-10-25 11:18:32 · 1179 阅读 · 0 评论 -
[LeetCode] 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 be:bool isMatch(c原创 2013-10-27 00:37:49 · 1057 阅读 · 0 评论 -
[LeetCode] Convert Sorted List to Binary Search Tree
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *//** * Definition for binary tree * stru原创 2013-10-23 09:38:47 · 562 阅读 · 0 评论 -
[LeetCode] Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without usi原创 2013-10-04 10:33:20 · 2000 阅读 · 0 评论 -
[LeetCode] Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to原创 2013-10-03 01:28:32 · 3970 阅读 · 0 评论 -
[LeetCode] Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Could you implement it without using extra memory?Solution: 利用异或的可交换性!!!!!!!!!!!!!!clas原创 2013-10-02 22:28:21 · 1545 阅读 · 0 评论 -
[LeetCode] Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be n原创 2013-06-09 07:08:24 · 2875 阅读 · 0 评论 -
[leetcode]Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.class Solution {public: vector anagrams(vector &strs) { // Start t原创 2013-06-19 08:03:35 · 853 阅读 · 0 评论 -
[LeetCode] Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.class Solution {public: string m原创 2013-06-26 03:11:51 · 816 阅读 · 0 评论 -
[LeetCode] Convert linked list to BST
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *//** * Definition for binary tree * stru原创 2013-08-22 12:59:56 · 642 阅读 · 0 评论 -
[LeetCode] Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BANC"原创 2013-08-26 00:20:19 · 4314 阅读 · 0 评论 -
[leetCode] Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integer原创 2013-08-25 23:13:16 · 805 阅读 · 0 评论 -
[LeetCode] Interleave String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc",原创 2013-03-05 06:56:09 · 2077 阅读 · 0 评论 -
[LeetCode] Recover Binary Search Tree
wo elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devise原创 2013-09-30 11:32:52 · 596 阅读 · 0 评论 -
[LeetCode] Trapping rain water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]原创 2013-09-16 23:53:56 · 926 阅读 · 0 评论 -
[LeetCode] longest consecutive sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3原创 2013-09-17 03:19:56 · 728 阅读 · 0 评论 -
[LeetCode] Word Ladder
1. Recursively: time limits exceedclass Solution {public: void ladder(string start, string end, unordered_set dict, int &minPath,int paths) { if(dict.empty()) return; if原创 2013-10-11 10:33:35 · 799 阅读 · 0 评论