
中
文章平均质量分 75
KiraYin--
这个作者很懒,什么都没留下…
展开
-
[leetCode] Integer to Roman
罗马字母规则见:https://zh.wikipedia.org/wiki/%E7%BD%97%E9%A9%AC%E6%95%B0%E5%AD%97因为相减减数只能是一位而且不能跨位数,相加同一个字母不能超过三个,所以可以先用一张对应表将相减能得到的数表示出来,并表述出4*10^n.class Solution {public: string intToRoman(int num原创 2013-06-20 03:26:04 · 972 阅读 · 0 评论 -
[LeetCode] HouseRobber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house原创 2015-07-07 11:29:03 · 830 阅读 · 0 评论 -
[LeetCode]Implement Trie (Prefix Tree)
class TrieNode {public: // Initialize your data structure here. TrieNode() { val='0'; end_of_a_word=0; for(int i=0;i<26;i++) {原创 2015-06-16 13:58:04 · 955 阅读 · 0 评论 -
[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 · 790 阅读 · 0 评论 -
[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 · 559 阅读 · 0 评论 -
[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 · 848 阅读 · 0 评论 -
[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 · 1892 阅读 · 0 评论 -
[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 · 5789 阅读 · 2 评论 -
[LeetCode] Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You原创 2013-03-14 08:35:09 · 2811 阅读 · 0 评论 -
[LeetCode] CLone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled from 0 to N - 1, where N is the total nod原创 2013-09-26 12:06:24 · 2060 阅读 · 0 评论 -
[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 · 776 阅读 · 0 评论 -
[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 · 821 阅读 · 0 评论 -
[leetCode] Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.class Solution {public: TreeNode *buildTree(vector原创 2013-08-27 07:59:52 · 838 阅读 · 0 评论 -
[LeetCode] Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [原创 2013-08-24 03:06:21 · 1028 阅读 · 0 评论 -
[LeetCode] Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()",原创 2013-08-11 00:05:49 · 2393 阅读 · 0 评论 -
[LeetCode]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 space.原创 2013-06-26 03:45:27 · 3039 阅读 · 1 评论 -
[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原创 2015-08-06 11:52:46 · 717 阅读 · 0 评论