![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 70
Yanito
小学生
展开
-
LeetCode@Array_169_Majority_Element
Problem:javapublic class Solution { int majorityElement(vector &num) { int vote = num[0]; int count = 1; int size = num.size(); //vote from the second number for( int i = 1;原创 2017-06-05 11:03:23 · 152 阅读 · 0 评论 -
LeetCode@Array_605_Can_Place_Flowers
Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die.Gi原创 2017-07-01 12:01:23 · 147 阅读 · 0 评论 -
LeetCode@HashTable_575_DistributeCandies
Problem:JAVA:import java.util.*;public class Solution { public int distributeCandies(int[] candies) { Set kinds = new HashSet<>(); int total = candies.length; for (int i = 0;原创 2017-06-09 23:39:09 · 147 阅读 · 0 评论 -
LeetCode@Tree_617_Merge_Two_Binary_Trees
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binary tr原创 2017-06-22 12:24:48 · 142 阅读 · 0 评论 -
LeetCode@String_412_Fizz_Buzz
Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. Fo原创 2017-07-02 11:59:47 · 175 阅读 · 0 评论 -
LeetCode@Bit_461_Hamming_Distance
Problem:The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance.原创 2017-06-23 12:03:13 · 171 阅读 · 0 评论 -
LeetCode@Tree_606_Construct_String_from_Binary_Tree
Problem:ou need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way.The null node needs to be represented by empty parenthesis pair "原创 2017-06-24 12:13:44 · 190 阅读 · 0 评论 -
LeetCode@Tree_112_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-25 07:45:54 · 159 阅读 · 0 评论 -
LeetCode@Tree_226_Invert_Binary_Tree
problem:invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1java:/** * Definition for a binary tree node. * public原创 2017-06-25 07:49:25 · 142 阅读 · 0 评论 -
LeetCode@HashMap_389_Find_the_Difference
389. Find the DifferenceDescriptionHintsSubmissionsSolutionsDiscuss Editorial SolutionPick OneGiven two strings s and t which consist of only lowercas原创 2017-06-26 10:43:51 · 200 阅读 · 0 评论 -
LeetCode@Tree_404_Sum_of_Left_Leaves
404. Sum of Left LeavesDescriptionHintsSubmissionsSolutionsDiscuss Editorial SolutionPick OneFind the sum of all left leaves in a given binary tree.原创 2017-06-26 23:10:12 · 187 阅读 · 0 评论 -
LeetCode@HashMap_404_Sum_of_Left_Leaves
Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.原创 2017-06-27 04:45:15 · 160 阅读 · 0 评论 -
LeetCode@543_Diameter_of_Binary_Tree
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may n原创 2017-06-28 11:22:42 · 151 阅读 · 0 评论 -
LeetCode@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原创 2017-06-28 11:24:55 · 173 阅读 · 0 评论 -
LeetCode@107_Binary_Tree_Level_Order_Traversal_II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree [3,9,20,null,null,15,原创 2017-06-28 11:27:14 · 197 阅读 · 0 评论 -
[LeetCode Solution 98]: Validate Binary Search Tree
[LeetCode Solution 98] Validate Binary Search Tree原创 2017-09-04 00:03:57 · 267 阅读 · 0 评论 -
[LeetCode 144] Binary Tree Preorder Traversal
Binary Tree Preorder Traversal原创 2017-08-27 12:00:06 · 222 阅读 · 0 评论 -
[LeetCode 145] Binary Tree Postorder Traversal
Question: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]Approach #1 Recursive [Accepted]De原创 2017-08-28 08:09:04 · 469 阅读 · 0 评论 -
LeetCode@Dynamic_70_Climbing_Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?java:public class原创 2017-07-01 11:59:11 · 150 阅读 · 0 评论 -
leetcode@Tree_563_Binary_Tree_Tilt
Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right subtre原创 2017-07-01 11:57:00 · 156 阅读 · 0 评论 -
LeetCode@Math_507_Perfect_Number
Problem:JAVApublic class Solution { public Boolean checkPerfectNumber(int num) { if (num < 2) return false; int sum = 1; for (int x = 2; x * x <= num; x++) { if (num % x原创 2017-06-09 12:10:10 · 214 阅读 · 0 评论 -
LeetCode@Tree_100_Same_Tree
Problem:JAVA:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */publ原创 2017-06-16 01:40:29 · 162 阅读 · 0 评论 -
LeetCode@Tree_572_Subtree_of_Another_Tree
Problem:JAVA:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */publ原创 2017-06-16 01:43:05 · 152 阅读 · 0 评论 -
LeetCode@Array_88_MergeSortedArray
Problem DiscriptionGiven two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equa原创 2017-06-01 05:21:17 · 273 阅读 · 0 评论 -
LeetCode@Array_268_Missing_Number
Problem:Java:public class Solution { public int missingNumber(int[] nums) { HashMap map = new HashMap<>(); for(int i = 0;i< nums.length;i++) { map.put(nums[i], i); } for(原创 2017-06-06 10:54:49 · 137 阅读 · 0 评论 -
LeetCode@Tree_101_Symmetric Tree
Problem:Java:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */pu原创 2017-06-17 11:21:09 · 138 阅读 · 0 评论 -
LeetCode@Tree_100_Max_Depth_B_Tree
104. Maximum Depth of Binary TreeDescriptionHintsSubmissionsSolutionsTotal Accepted: 241399Total Submissions: 462901Difficulty: EasyContributor: LeetCodeGiven原创 2017-06-18 10:43:42 · 227 阅读 · 0 评论 -
LeetCode@Tree_110_Balanced_Binary_Tree
110. Balanced Binary TreeDescriptionHintsSubmissionsSolutionsTotal Accepted: 172600Total Submissions: 465133Difficulty: EasyContributor: LeetCodeGiven a binar原创 2017-06-18 18:58:25 · 152 阅读 · 0 评论 -
LeetCode@Array_136_Single_Number
Problem:Java public class Solution {public int singleNumber(int[] nums) { HashMap map = new HashMap<>(); Integer key = null; for (int i = 0; i < nums.length; i++) { if (!map.contain原创 2017-06-07 12:49:44 · 207 阅读 · 0 评论 -
LeetCode@LinkedList_21_Merge_Two_Sorted_Lists
Problem DiscriptionGiven two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or eq原创 2017-06-01 21:15:39 · 187 阅读 · 0 评论 -
LeetCode@Array_414_Third_Maximum_Number
Problem:Algorithm:策略:每加入一个元素,判断这个元素1st_max? 2nd_max? 3rd_max; 判断方式如代码所示注意⚠️:return 判断是否是long最小值用于返回没有3rd_max的情况,此时返回1st_max;Java :public class Solution { public int thirdMax(int原创 2017-06-03 11:40:12 · 183 阅读 · 0 评论 -
LeetCode@Stack_20_Valid_Parentheses
20. Valid ParenthesesDescriptionHintsSubmissionsSolutionsTotal Accepted: 202863Total Submissions: 612017Difficulty: EasyContributor: LeetCodeGiven a string co原创 2017-06-19 11:49:08 · 184 阅读 · 0 评论 -
LeetCode@513_Find_Bottom_Left_Tree_Value
Given a binary tree, find the leftmost value in the last row of the tree.Example 1:Input: 2 / \ 1 3Output:1Example 2: Input: 1 / \ 2 3原创 2017-06-29 11:25:52 · 174 阅读 · 0 评论 -
LeetCode@111_Minimum_Depth_of_Binary_Tree
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.java:/** * Definition f原创 2017-06-29 11:28:18 · 156 阅读 · 0 评论 -
LeetCode@Array_215_Kth_Largest_Element_in_an_Array
Problem:Algorithm算法导论:Order StatisticJava:public class Solution { public int findKthLargest(int[] a, int k) { int n = a.length; int p = quickSelect(a, 0, n - 1, n - k + 1);原创 2017-06-04 11:22:54 · 162 阅读 · 0 评论 -
LeetCode@DFS_257_Binary_Tree_Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]jav原创 2017-06-20 11:43:56 · 154 阅读 · 0 评论 -
LeetCode@Array_35_Search_Insert_Position
Problem:javapublic class Solution {public int searchInsert(int[] nums, int target) { int index = 0; for(int i =0;i<nums.length;i++) { if(nums[i] == target) { index = i; b原创 2017-06-08 12:40:08 · 162 阅读 · 0 评论 -
LeetCode@DFS_257_Binary_Tree_Paths
Problem:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.Java:/** * Definition for a binary tree node. * public class TreeNode { * int val;原创 2017-06-20 20:01:40 · 194 阅读 · 0 评论 -
[LeetCode Solution 54] Spiral Matrix
Question:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7原创 2017-09-03 02:44:55 · 249 阅读 · 0 评论