- 博客(19)
- 资源 (4)
- 收藏
- 关注
原创 [LeetCode] Remove Duplicate from Sorted Linkded List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1-
2013-10-30 09:31:31 765
原创 [LeetCode] Merge K sorted lists
Solution 1:1. use merge2list(), and merge all lists one by one. Time complexity is O(n*longest list length)2. For each node, find the smallest node among all head nodes in O(k) time, Time complexi
2013-10-27 12:09:01 815
原创 [LeetCode] 2Sum, 3Sum, 4Sum, 3SUm closet
1. 2Sum: hash Table O(n*n)2. 3Sum: 2Sum + 1 : O(n*n)for loop + 左右夹逼法:O(N*N)class Solution {public: vector > threeSum(vector &num) { // Note: The Solution object is instantiated
2013-10-27 09:31:52 1853
原创 [LeetCode] Roman to Integer and Integer to Roman
羅馬數字共有7個,即I(1)、V(5)、X(10)、L(50)、C(100)、D(500)和M(1000)。按照下述的規則可以表示任意正整數。需要注意的是罗马数字中没有“0”,與進位制無關。一般認為羅馬數字只用來記數,而不作演算。重複數次:一個羅馬數字重複幾次,就表示這個數的幾倍。右加左減:在較大的羅馬數字的右邊記上較小的羅馬數字,表示大數字加小數字。在較大的羅馬數字的左邊
2013-10-27 04:19:22 5740 2
原创 [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 1039
原创 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 1159
原创 [LeetCode] Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of
2013-10-24 11:28:07 678
原创 [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 617
原创 [LeetCode] Binary Tree Zigzag level order traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary
2013-10-23 12:13:42 532
原创 [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 535
原创 [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 603
原创 [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 697
原创 [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 633
原创 [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 774
原创 [LeetCode] Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region .For example,X X X XX O O
2013-10-09 12:36:33 757
原创 [LeetCode] Scramble String
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ gr
2013-10-05 01:08:57 793
原创 [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 1967
原创 [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 3925
原创 [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 1524
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人