leetcode
文章平均质量分 71
橙子爱吃蛋
慢慢成长,做一个高级的程序员。
展开
-
leetcode结题技巧
数组1.乘 10 操作和累加操作都可能造成溢出。对于溢出的处理方式通常可以转换为 INT_MAX 的逆操作。比如判断某数乘 10 是否会溢出,那么就把该数和 INT_MAX 除 10 进行比较。字符串1.原创 2020-11-22 16:57:15 · 148 阅读 · 0 评论 -
leetcode解题记录
【2020/10/08】1.leetcode 48 旋转图像https://leetcode-cn.com/problems/rotate-image/solution/li-kou-48xiao-bai-du-neng-kan-dong-de-fang-fa-zhu-/https://leetcode-cn.com/problems/rotate-image/solution/xuan-zhuan-tu-xiang-by-leetcode/原创 2020-10-08 16:07:48 · 244 阅读 · 0 评论 -
leetcode question 103 : 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 tre...原创 2018-04-24 21:37:24 · 116 阅读 · 0 评论 -
leetcode question 104 : Maximum Depth of Binary Tree
问题: 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.Note: A leaf is a node with no...原创 2018-04-24 21:48:42 · 132 阅读 · 0 评论 -
leetcode question 105 : 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.For example, givenpreorder = [3,9,20,15,7]inorder = [9,3,15,2...原创 2018-05-10 16:48:36 · 169 阅读 · 0 评论 -
leetcode question 106 :Construct Binary Tree from Inorder and Postorder Traversal
问题:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.For example, giveninorder = [9,3,15,20,7]postorder = [9,15,7...原创 2018-05-10 16:57:46 · 137 阅读 · 0 评论 -
leetcode question 116、117: Populating Next Right Pointers in Each Node(Ⅱ)
问题: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 ...原创 2018-10-02 21:04:42 · 131 阅读 · 0 评论 -
leetcode question 129: Sum Root to Leaf Numbers
问题: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.Find the...原创 2018-10-02 22:03:28 · 146 阅读 · 0 评论 -
leetcode question 144:Binary Tree Preorder Traversal
问题:Given a binary tree, return the preorder traversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,2,3]Follow up: Recursive solution is trivial, ...原创 2018-10-03 21:01:15 · 147 阅读 · 0 评论 -
leetcode question 145:Binary Tree Postorder Traversal
问题:Given a binary tree, return the postorder traversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [3,2,1]Follow up: Recursive solution is trivial,...原创 2018-10-03 21:24:35 · 127 阅读 · 0 评论 -
leetcode question 114: Flatten Binary Tree to Linked List
问题:Given a binary tree, flatten it to a linked list in-place.For example, given the following tree: 1 / \ 2 5 / \ \3 4 6The flattened tree should look like:1 \ 2 \...原创 2018-09-27 10:46:25 · 126 阅读 · 0 评论 -
leetcode question 113: Path Sum II
问题:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.Note: A leaf is a node with no children.Example:Given the below binary tree and sum = 2...原创 2018-09-27 10:56:30 · 161 阅读 · 0 评论 -
leetcode question 199:Binary Tree Right Side View
问题: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.Example:Input: [1,2,3,null,5,null,4]Output: [1,...原创 2018-10-06 20:53:09 · 165 阅读 · 0 评论 -
leetcode question 102 : Binary Tree Level Order Traversal
问题: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 / \ 9 20 /...原创 2018-04-24 21:07:01 · 147 阅读 · 0 评论 -
leetcode question 100:Same Tree
题目:Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Example 1...原创 2018-04-12 11:54:07 · 158 阅读 · 0 评论 -
leetcode question 96:Unique Binary Search Trees
转自:点击打开链接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 1 \...转载 2018-03-27 20:43:55 · 151 阅读 · 0 评论 -
leetcode question 27:Remove Element
问题:Given an array and a value, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input array in-pla...原创 2018-03-06 20:23:45 · 124 阅读 · 0 评论 -
leetcode question 31:Next Permutation
问题: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 lowest possible ...原创 2018-03-07 14:41:20 · 148 阅读 · 0 评论 -
leetcode question 33:Search in Rotated Sorted Array
问题:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in th...原创 2018-03-07 15:30:02 · 98 阅读 · 0 评论 -
leetcode question 34:Search for a Range
问题:Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the targe...原创 2018-03-07 20:21:46 · 131 阅读 · 0 评论 -
leetcode question 35:Search Insert Position
问题:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.E...原创 2018-03-09 10:20:06 · 136 阅读 · 0 评论 -
leetcode question 16: 3Sum Closest
问题:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exac...原创 2018-03-02 11:11:20 · 141 阅读 · 0 评论 -
leetcode question 18: 4Sum
问题:Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution se...原创 2018-03-05 23:43:36 · 159 阅读 · 0 评论 -
leetcode question 42: Trapping Rain Water
问题:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], r...原创 2018-03-14 16:30:41 · 148 阅读 · 0 评论 -
leetcode question 41:First Missing Positive
问题:Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant space.分析...原创 2018-03-14 16:49:41 · 150 阅读 · 0 评论 -
leetcode question 94:Binary Tree Inorder Traversal
题目: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: Recursive solution is trivial, co...原创 2018-03-26 11:22:38 · 131 阅读 · 0 评论 -
leetcode question 95: Unique Binary Search Trees II
题目:Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 ...原创 2018-04-02 19:43:19 · 133 阅读 · 0 评论 -
leetcode question 98:Validate Binary Search Tree
转载自:StudyCoder题目:验证二叉搜索树Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than t...转载 2018-04-02 20:39:50 · 124 阅读 · 0 评论 -
leetcode question 26:Remove Duplicates from Sorted Array
问题:Given a sorted array, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by modifying t...原创 2018-03-06 19:53:42 · 163 阅读 · 0 评论