C++
DarrenXf
这个作者很懒,什么都没留下…
展开
-
word-ladder leetcoder C++
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a time Each intermediate word mu...原创 2018-09-24 18:11:54 · 235 阅读 · 0 评论 -
copy-list-with-random-pointer leetcode C++
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list. C++/** * Definition for sin...原创 2018-09-21 11:34:10 · 283 阅读 · 0 评论 -
distinct-subsequences leetcode C++
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 none)...原创 2018-09-21 11:34:16 · 250 阅读 · 0 评论 -
evaluate-reverse-polist-notation leetcode C++
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another expression.Some examples:["2", "1", "+", "3", "*"]...原创 2018-09-21 11:34:22 · 197 阅读 · 0 评论 -
gas-station leetcode C++
There are N gas stations along a circular route, where the amount of gas at station i isgas[i].You have a car with an unlimited gas tank and it costscost[i]of gas to travel from station i to its nex...原创 2018-09-21 11:34:29 · 298 阅读 · 0 评论 -
insertion-sort-list leetcode C++
Sort a linked list using insertion sort.C++/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * ...原创 2018-09-22 10:57:16 · 219 阅读 · 0 评论 -
linked-list-cycle-ii leetcode C++
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up: Can you solve it without using extra space?C++/** * Definition for singly-linked list....原创 2018-09-22 10:57:25 · 161 阅读 · 0 评论 -
linked-list-cycle leetcode C++
Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?C++/** * Definition for singly-linked list. * struct ListNode { * int val; *...原创 2018-09-22 10:57:32 · 171 阅读 · 0 评论 -
longest-consecutive-sequence leetcode C++
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, 4]. ...原创 2018-09-22 10:57:39 · 185 阅读 · 0 评论 -
clone-graph leetcode C++
Clone an undirected graph. Each node in the graph contains alabeland a list of itsneighbors.OJ's undirected graph serialization: Nodes are labeled uniquely.We use#as a separator for each node, and...原创 2018-09-21 11:34:03 · 161 阅读 · 0 评论 -
candy leetcode C++
There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least one ca...原创 2018-09-21 11:33:56 · 269 阅读 · 0 评论 -
高度最小的BST 牛客网 程序员面试金典 C++ Python
高度最小的BST 牛客网 程序员面试金典 C++ Python 题目描述 对于一个元素各不相同且按升序排列的有序序列,请编写一个算法,创建一棵高度最小的二叉查找树。 给定一个有序序列int[] vals,请返回创建的二叉查找树的高度。 C++class MinimalBST {public://run:3ms memory:476k int buil...原创 2018-09-20 00:39:42 · 602 阅读 · 0 评论 -
balanced-binary-tree leetcode C++
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ ...原创 2018-09-20 00:39:56 · 222 阅读 · 0 评论 -
best-time-to-buy-and-sell-stock-ii leetcode C++
Say you have an array for which the i th 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 like (ie, buy one...原创 2018-09-20 00:40:07 · 131 阅读 · 0 评论 -
best-time-to-buy-and-sell-stock-iii leetcode C++
Say you have an array for which the i th 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 may not ...原创 2018-09-20 00:40:15 · 217 阅读 · 0 评论 -
best-time-to-buy-and-sell-stock leetcode C++
Say you have an array for which the i th 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 of the stock), ...原创 2018-09-21 11:33:27 · 244 阅读 · 0 评论 -
binary-tree-maximum-path-sum leetcode C++
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example: Given the below binary tree, 1 / \ 2 3Return6.C++/** * Definition ...原创 2018-09-21 11:33:34 · 128 阅读 · 0 评论 -
binary-tree-postorder-traversal leetcode C++
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: Recursive solution is trivial, could you ...原创 2018-09-21 11:33:41 · 165 阅读 · 0 评论 -
binary-tree-preorder-traversal leetcode C++
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].Note: Recursive solution is trivial, could you do it itera...原创 2018-09-21 11:33:49 · 181 阅读 · 0 评论 -
max-points-on-a-line leetcode C++
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.C++/** * Definition for a point. * struct Point { * int x; * int y; * Point() :...原创 2018-09-22 10:57:47 · 231 阅读 · 0 评论 -
minimum-depth-of-binary-tree leetcode C++
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.C++class Solution {public: //run...原创 2018-09-22 10:57:57 · 129 阅读 · 0 评论 -
single-number leetcode C++
Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra ...原创 2018-09-23 00:41:08 · 208 阅读 · 0 评论 -
sort-list leetcode C++
Sort a linked list in O(n log n) time using constant space complexity.C++/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int ...原创 2018-09-23 00:41:14 · 358 阅读 · 0 评论 -
sum-root-to-leaf-numbers leetcode C++
Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number123.Find the total sum...原创 2018-09-23 00:41:20 · 209 阅读 · 0 评论 -
surrounded-regions leetcode C++
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 X X O O X X X O X X O X ...原创 2018-09-23 00:41:26 · 410 阅读 · 0 评论 -
triangle leetcode C++
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], [6,5,7], [4,1,8,3...原创 2018-09-24 18:11:24 · 250 阅读 · 0 评论 -
valid-palindrome leetcode C++
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example, "A man, a plan, a canal: Panama"is a palindrome. "race a car"is not a palind...原创 2018-09-24 18:11:30 · 168 阅读 · 0 评论 -
word-break-ii leetcode C++
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, given s ="catsan...原创 2018-09-24 18:11:39 · 396 阅读 · 0 评论 -
word-break leetcoder C++
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, given s ="leetcode", dict =["leet", "cod...原创 2018-09-24 18:11:47 · 231 阅读 · 0 评论 -
single-number-ii leetcode C++
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 using ...原创 2018-09-23 00:41:02 · 301 阅读 · 0 评论 -
reorder-list leetcode C++
Given a singly linked list L: L 0→L 1→…→L n-1→L n, reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→…You must do this in-place without altering the nodes' values.For example, Given{1,2,3,4}, reorder it...原创 2018-09-23 00:40:56 · 274 阅读 · 0 评论 -
palindrome-partitioning-ii leetcode C++
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", Return1since...原创 2018-09-22 10:58:03 · 143 阅读 · 0 评论 -
palindrome-partitioning leetcode C++
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s ="aab", Return[ ["aa","b"], ["a","a...原创 2018-09-22 10:58:09 · 176 阅读 · 0 评论 -
pascals-triangle-ii leetcode C++
Given an index k, return the k th row of the Pascal's triangle.For example, given k = 3, Return[1,3,3,1].Note: Could you optimize your algorithm to use only O(k) extra space?C++class Solution...原创 2018-09-22 10:58:15 · 136 阅读 · 0 评论 -
pascals-triangle leetcode C++
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] ]C++class Solution {public: vector<v...原创 2018-09-22 10:58:21 · 258 阅读 · 0 评论 -
path-sum-ii leetcode C++
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 andsum = 22, 5 / 4 8 / / 11 13 4 / \ / 7 2 5 1 retur...原创 2018-09-23 00:40:23 · 214 阅读 · 0 评论 -
path-sum leetcode C++
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 tree andsum = ...原创 2018-09-23 00:40:32 · 217 阅读 · 0 评论 -
populating-next-right-pointers-in-each-node-ii leetcode C++
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 extra ...原创 2018-09-23 00:40:40 · 172 阅读 · 0 评论 -
populating-next-right-pointers-in-each-node leetcode C++
Given a binary treestruct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next;}Populate each next pointer to point to its next right node. If there is no next right...原创 2018-09-23 00:40:48 · 189 阅读 · 0 评论 -
集合栈 牛客网 程序员面试金典 C++ Python
集合栈 牛客网 程序员面试金典 C++ Python题目描述 请实现一种数据结构SetOfStacks,由多个栈组成,其中每个栈的大小为size,当前一个栈填满时,新建一个栈。该数据结构应支持与普通栈相同的push和pop操作。 给定一个操作序列int[][2] ope(C++为vector&ltvector&ltint>>),每个操作的第一个数代表操作类型,若...原创 2018-09-20 00:39:31 · 225 阅读 · 0 评论