C++
文章平均质量分 53
胡为乎遑遑于何之
桃花坞里桃花庵,桃花庵下桃花仙。
桃花仙人种桃树,又摘桃花换酒钱。
酒醒只在花前坐,酒醉还来花下眠。
半醒半醉日复日,花开花落年复年。
只愿老死花丛间。不愿鞠躬车马前。
车尘马足贵者趣,酒盏花枝贫者缘。
若将富贵比贫贱,一在平地一在天。
若将贫贱比车马,他得驱驰我得闲。
别人笑我太疯癫,我笑他人看不穿。
不见五陵豪杰墓,无花无酒锄作田。
展开
-
LeetCode (Divide Two Integers)
Problem:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.Solution:class Solution {public: int divide(int dividend, int d原创 2017-04-25 17:47:09 · 113 阅读 · 0 评论 -
LeetCode (Remove Duplicates from Sorted List II)
Problem;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原创 2017-05-19 09:45:49 · 191 阅读 · 0 评论 -
LeetCode ( Minimum Depth of Binary Tree)
Problem:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Solution:/** * Defi原创 2017-06-05 20:24:49 · 133 阅读 · 0 评论 -
LeetCode (Remove Duplicates from Sorted List)
Problem:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.Solution:原创 2017-05-21 22:40:00 · 124 阅读 · 0 评论 -
LeetCode (Binary Tree Level Order Traversal)
Problem:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3原创 2017-06-02 22:13:04 · 150 阅读 · 0 评论 -
LeetCode (Flatten Binary Tree to Linked List)
Problem:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look l原创 2017-06-19 11:38:15 · 143 阅读 · 0 评论 -
LeetCode (Binary Tree Zigzag Level Order Traversal)
Problem: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:原创 2017-06-03 21:16:03 · 178 阅读 · 0 评论 -
LeetCode (Maximum Depth of Binary Tree)
Problem:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Solution1:/** * Def原创 2017-06-04 10:03:58 · 242 阅读 · 0 评论 -
LeetCode (Populating Next Right Pointers in Each Node)
Problem:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its nex原创 2017-06-20 17:02:29 · 153 阅读 · 0 评论 -
LeetCode (Spiral Matrix II)
Problem:Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ],原创 2017-05-09 21:50:05 · 163 阅读 · 0 评论 -
LeetCode (Remove Duplicates from Sorted Array II)
Problem:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, wit原创 2017-05-18 16:19:01 · 158 阅读 · 0 评论 -
LeetCode (Minimum Window Substring)
Problem: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原创 2017-05-16 16:43:45 · 206 阅读 · 0 评论 -
LeetCode (Insert Interval)
Problem:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their sta原创 2017-05-08 13:08:33 · 131 阅读 · 0 评论 -
LeetCode (Reverse Linked List II)
Problem:Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m,原创 2017-05-26 22:51:49 · 130 阅读 · 0 评论 -
LeetCode (Binary Tree Inorder Traversal)
Problem:Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,3,2].Note:原创 2017-05-27 13:41:18 · 142 阅读 · 0 评论 -
LeetCode (Subsets)
Problem:Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[原创 2017-05-17 21:20:26 · 124 阅读 · 0 评论 -
LeetCode (Substring with Concatenation of All Words)
Problem:You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exa原创 2017-04-26 19:30:26 · 65 阅读 · 0 评论 -
LeetCode (Unique Binary Search Trees)
Problem:Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2原创 2017-05-28 11:23:09 · 155 阅读 · 0 评论 -
LeetCode (Next Permutation)
Problem:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the l原创 2017-04-27 11:26:12 · 113 阅读 · 0 评论 -
LeetCode (Single Number II)
Problem:Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one.Solution:class Solution {public: int singleNumber(原创 2017-06-29 23:04:23 · 151 阅读 · 0 评论 -
LeetCode (Insertion Sort List)
Problem:Sort a linked list using insertion sort.Solution:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x),原创 2017-07-10 15:49:17 · 132 阅读 · 0 评论 -
LeetCode ( Populating Next Right Pointers in Each Node II)
Problem: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原创 2017-06-21 19:37:30 · 140 阅读 · 0 评论 -
LeetCode (Path Sum II)
Problem:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5原创 2017-06-14 20:52:56 · 148 阅读 · 0 评论 -
LeetCode (Longest Consecutive Sequence)
Problem: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 sequen原创 2017-06-27 19:35:49 · 174 阅读 · 0 评论 -
LeetCode (Binary Tree Postorder Traversal)
Problem:Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: R原创 2017-07-09 12:40:01 · 138 阅读 · 0 评论 -
LeetCode (Largest Number)
Problem:Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The re原创 2017-07-24 09:44:28 · 205 阅读 · 0 评论 -
LeetCode (Binary Tree Right Side View)
Problem:Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary原创 2017-08-16 18:37:35 · 195 阅读 · 0 评论 -
Reverse Linked List
Problem:Reverse a singly linked list.链表问题80%可以用递归!Solutions:C++/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x)原创 2017-11-08 11:25:42 · 158 阅读 · 0 评论 -
LeetCode (Count Primes)
Problem:Description:Count the number of prime numbers less than a non-negative number, n.Solutions:C++:class Solution {public: int countPrimes(int n) { vector isPrime(n, true)原创 2017-11-01 10:57:19 · 151 阅读 · 0 评论 -
LeetCode (Add Two Numbers)
问题:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and ret原创 2017-03-25 19:58:16 · 185 阅读 · 0 评论 -
LeetCode (Sum Root to Leaf Numbers)
Problem:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.F原创 2017-06-26 18:09:36 · 150 阅读 · 0 评论 -
LeetCode (Binary Tree Preorder Traversal)
Problem:Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Solution:原创 2017-07-05 16:22:57 · 135 阅读 · 0 评论 -
LeetCode (Pascal's Triangle)
Problem:Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]Solution:cla原创 2017-06-22 16:16:21 · 160 阅读 · 0 评论 -
LeetCode (Min Stack)
Problem:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack原创 2017-07-12 09:34:27 · 156 阅读 · 0 评论 -
LeetCode (Linked List Cycle II)
Problem:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Solution:/** * Definition for singly-linked list. * struct ListNode { * int val;原创 2017-07-03 20:04:47 · 128 阅读 · 0 评论 -
LeetCode (Triangle)
Problem: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],原创 2017-06-23 22:21:34 · 187 阅读 · 0 评论 -
LeetCode (Best Time to Buy and Sell Stock)
Problem:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share原创 2017-06-24 14:03:10 · 165 阅读 · 0 评论 -
LeetCode (Best Time to Buy and Sell Stock II)
Problem: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 as many transactions as you li原创 2017-06-25 13:12:17 · 167 阅读 · 0 评论 -
LeetCode (Reorder List)
Problem:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4},原创 2017-07-04 18:32:09 · 134 阅读 · 0 评论 -
LeetCode (Path Sum)
Problem:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary原创 2017-06-13 21:53:51 · 134 阅读 · 0 评论