![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 71
Pokemon_Master
记录学习的点点滴滴
展开
-
Leetcode——Sort Array By Parity(905)(持续更新)
Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A.You may return any answer array that satisfies this conditi...原创 2018-09-16 17:10:14 · 488 阅读 · 0 评论 -
LeetCode——Leaf-Similar Trees(872)
Consider all the leaves of a binary tree. From left to right order, the values of those leaves form a leaf value sequence.For example, in the given tree above, the leaf value sequence is (6, 7, 4...原创 2018-10-11 09:37:39 · 141 阅读 · 0 评论 -
LeetCode——Merge k Sorted Lists(23)
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[ 1->4->5, 1->3->4, 2->6]Output: 1->1->2->3->4-...原创 2018-09-26 15:41:04 · 140 阅读 · 0 评论 -
LeetCode—— Longest Consecutive Sequence(128)
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.Your algorithm should run in O(n) complexity.Example:Input: [100, 4, 200, 1, 3, 2]Output: 4Ex...原创 2018-09-27 14:00:11 · 136 阅读 · 0 评论 -
LeetCode——N-ary Tree Postorder Traversal(590)
Given an n-ary tree, return the postorder traversal of its nodes' values. For example, given a 3-ary tree: Return its postorder traversal as: [5,6,3,2,4,1]. 分析:典型的树遍历代码:/*// Defi...原创 2018-09-23 08:29:29 · 218 阅读 · 0 评论 -
LeetCode——N-ary Tree Postorder Traversal(590)
Given an n-ary tree, return the postorder traversal of its nodes' values. For example, given a 3-ary tree: Return its postorder traversal as: [5,6,3,2,4,1]. Note: Recursive solution is t...原创 2018-10-09 12:19:59 · 147 阅读 · 0 评论 -
LeetCode——sort list(148)
Sort a linked list in O(n log n) time using constant space complexity.Example 1:Input: 4->2->1->3Output: 1->2->3->4Example 2:Input: -1->5->3->4->0Output: -1-...原创 2018-10-10 10:36:42 · 121 阅读 · 0 评论 -
LeetCode——Uncommon Words from Two Sentences(884)
We are given two sentences A and B. (A sentence is a string of space separated words. Each word consists only of lowercase letters.)A word is uncommon if it appears exactly once in one of the sent...原创 2018-10-16 22:58:14 · 147 阅读 · 0 评论 -
LeetCode——Maximum Depth of N-ary Tree(559)
Given a n-ary 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.For example, given a 3-ary tree: ...原创 2018-10-17 10:08:47 · 145 阅读 · 0 评论 -
LeetCode——Convert Sorted Array to Binary Search Tree(108)
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the...原创 2018-10-31 09:13:50 · 114 阅读 · 0 评论 -
LeetCode——Trim a Binary Search Tree(669)
Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the re...原创 2018-10-31 15:08:18 · 142 阅读 · 0 评论 -
LeetCode——Move Zeroes(283)
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.Example:Input: [0,1,0,3,12]Output: [1,3,12,0,0]Note:You m...原创 2018-09-26 09:13:49 · 109 阅读 · 0 评论 -
LeetCode——Array Partition I(561)
Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as poss...原创 2018-09-15 15:09:39 · 110 阅读 · 0 评论 -
LeetCode——Self Dividing Numbers(728)
A self-dividing number is a number that is divisible by every digit it contains.For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.Also, a self-dividin...原创 2018-09-17 11:16:08 · 111 阅读 · 0 评论 -
LeetCode ——word-break
题目描述 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, givens ="leetcode",dict =["leet...原创 2018-09-17 18:55:38 · 213 阅读 · 0 评论 -
LeetCode——work-break-ii(140)
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible ...原创 2018-09-18 12:25:26 · 188 阅读 · 0 评论 -
LeetCode——Palindrome Partitioning II(132)
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.Example:Input: "aab"Output: 1Explana...原创 2018-09-18 16:17:51 · 158 阅读 · 0 评论 -
LeetCode——461.Hamming Distance
问题: 这道问题实际上是求两个数里1不一样的位数。我一开始的答案是如下:class Solution {public: int hammingDistance(int x, int y) { int flag = 1; int count = 0; for(int i ...原创 2018-09-13 17:48:40 · 159 阅读 · 0 评论 -
LeetCode——Triangle(120)
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...原创 2018-09-19 09:55:49 · 138 阅读 · 0 评论 -
LeetCode——Shortest Distance to a Character(821)
Given a string S and a character C, return an array of integers representing the shortest distance from the character C in the string.Example 1:Input: S = "loveleetcode", C = 'e'Output: [3, 2, 1...原创 2018-09-24 08:59:07 · 106 阅读 · 0 评论 -
LeetCode——Distinct Subsequences(115)
Given a string S and a string T, count the number of distinct subsequences of S which equals T.A subsequence of a string is a new string which is formed from the original string by deleting some (ca...原创 2018-09-19 16:58:43 · 150 阅读 · 0 评论 -
LeetCode——Peak Index in a Mountain Array(852)
Let's call an array A a mountain if the following properties hold:A.length >= 3 There exists some 0 < i < A.length - 1 such that A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ....原创 2018-09-14 15:51:57 · 125 阅读 · 0 评论 -
LeetCode——Single Number(136)
Given a non-empty 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 us...原创 2018-09-25 19:11:07 · 119 阅读 · 0 评论 -
LeetCode——Maximum Binary Tree(654)
Given an integer array with no duplicates. A maximum tree building on this array is defined as follow:The root is the maximum number in the array. The left subtree is the maximum tree constructed f...翻译 2018-11-01 09:57:40 · 164 阅读 · 0 评论