![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
水木今山
什么都没有
展开
-
LeetCode#530: Minimum Absolute Difference in BST
DescriptionGiven a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.ExampleInput: 1 \ 3 / 2Output:1Explanat...原创 2019-01-23 11:52:54 · 122 阅读 · 0 评论 -
LeetCode#190: Reverse Bits
DescriptionReverse bits of a given 32 bits unsigned integer.ExampleInput: 43261596Output: 964176192Explanation: 43261596 represented in binary as 00000010100101000001111010011100, r...原创 2018-11-19 09:03:56 · 98 阅读 · 1 评论 -
LeetCode#784: Letter Case Permutation
DescriptionGiven a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible strings we could create.ExampleInput: S...原创 2018-11-16 12:12:22 · 205 阅读 · 0 评论 -
LeetCode#859: Buddy Strings
DescriptionGiven two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B.ExampleInput: A = "ab", B = "ba"Output: trueInput: ...原创 2018-11-12 12:23:02 · 136 阅读 · 0 评论 -
LeetCode#367: Valid Perfect Square
DescriptionGiven a positive integer num, write a function which returns True if num is a perfect square else False.ExampleInput: 16Output: trueInput: 14Output: falseSolution二分查找法最容易想到的一种方法便...原创 2018-11-13 17:11:50 · 189 阅读 · 0 评论 -
LeetCode#67: Add Binary
DescriptionGiven two binary strings, return their sum (also a binary string).The input strings are both non-empty and contains only characters 1 or 0.ExampleInput: a = "11", b = "1"Output: "100"...原创 2018-11-07 17:06:56 · 81 阅读 · 0 评论 -
LeetCode#696: Count Binary Substrings
DescriptionGive a string s, count the number of non-empty (contiguous) substrings that have the same number of 0’s and 1’s, and all the 0’s and all the 1’s in these substrings are grouped consecutive...原创 2018-11-10 12:23:19 · 260 阅读 · 0 评论 -
LeetCode#686: Repeated String Match
DescriptionGiven two strings A and B, find the minimum number of times A has to be repeated such that B is a substring of it. If no such solution, return -1.For example, with A = “abcd” and B = “cda...原创 2018-11-10 11:51:11 · 304 阅读 · 0 评论 -
LeetCode#234: Palindrome Linked List
DescriptionGiven a singly linked list, determine if it is a palindrome.class ListNode { int val; ListNode next; ListNode(int x) { val = x; }}ExampleExample 1:Input: 1->2Output:...原创 2018-11-04 10:35:43 · 116 阅读 · 0 评论 -
LeetCode#680: Valid Palindrome II
DescriptionGiven a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.ExampleInput: "aba"Output: TrueInput: "abca"Output: TrueExplanation: You...原创 2018-11-09 17:05:05 · 122 阅读 · 0 评论 -
LeetCode#21: Merge Two Sorted Lists
DescriptionMerge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.ExampleExample:Input: 1->2->4, 1->...原创 2018-11-01 11:49:51 · 109 阅读 · 0 评论 -
LeetCode#897: Increasing Order Search Tree
DescriptionGiven a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only 1 right child.ExampleExample 1:...原创 2018-11-21 16:55:15 · 148 阅读 · 0 评论 -
LeetCde#198: House Robber
DescriptionYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that ad...原创 2018-11-15 12:06:18 · 157 阅读 · 0 评论 -
树的前中后层序遍历(递归与非递归方式)
Description此题与429、589题型类似,因此放在一起总结。![](590. N-ary Tree Postorder Traversal)()对于上图要求求出前序遍历、后序遍历和层级遍历的结果。Example前序遍历结果:[1,3,5,6,2,4]后序遍历结果:[5,6,3,2,4,1]层级遍历结果:[ [1], [3,2,4], [5,6...原创 2018-11-22 11:58:25 · 271 阅读 · 0 评论 -
LeetCode#543: Diameter of Binary Tree
DescriptionGiven 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 ...原创 2019-01-20 11:40:58 · 123 阅读 · 0 评论 -
LeeCode#172: Factorial Trailing Zeroes
DescriptionGiven an integer n, return the number of trailing zeroes in n!.ExampleExample 1:Input: 3Output: 0Explanation: 3! = 6, no trailing zero.Example 2:Input: 5Output: 1Explanation: 5!...原创 2019-01-24 22:21:48 · 177 阅读 · 0 评论 -
LeetCode#168: Excel Sheet Column Title
DescriptionGiven a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA ...原创 2019-01-24 22:05:15 · 168 阅读 · 0 评论 -
LeetCode#110: Balanced Binary Tree
DescriptionGiven 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 n...原创 2018-11-27 11:58:26 · 155 阅读 · 0 评论 -
LeetCode: Symmetric Tree
DescriptionGiven a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 ...原创 2018-11-23 15:17:39 · 108 阅读 · 0 评论 -
LeetCode#108: Convert Sorted Array to Binary Search Tree
DescriptionGiven 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 d...原创 2018-11-23 11:51:42 · 87 阅读 · 0 评论 -
LeetCode#405: Convert a Number to Hexadecimal
DescriptionGiven an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.ExampleInput:26Output:"1a"Input:-1Output:"ffffffff"No...原创 2018-11-18 11:59:59 · 143 阅读 · 0 评论 -
LeetCode#476: Number Complement
DescriptionGiven a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.NoteThe given integer is guaranteed to fit within the ra...原创 2018-11-18 11:48:06 · 204 阅读 · 1 评论 -
LeetCode#703: Kth Largest Element in a Stream
DescriptionDesign a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.Your KthLargest class will have a con...原创 2018-11-18 11:35:18 · 475 阅读 · 0 评论 -
LeetCode#496: Next Greater Element I
DescriptionYou are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1’s elements in the corresponding places...原创 2018-11-17 12:06:50 · 120 阅读 · 0 评论 -
LeetCode#594: LongestHarmoniousSubsequence
DescriptionWe define a harmonious array is an array where the difference between its maximum value and its minimum value is exactly 1.Now, given an integer array, you need to find the length of its ...原创 2018-10-30 17:16:56 · 107 阅读 · 0 评论 -
LeetCode#690: Employee Importance
DescriptionYou are given a data structure of employee information, which includes the employee’s unique id, his importance value and his direct subordinates’ id.For example, employee 1 is the leader...原创 2018-10-30 17:00:08 · 116 阅读 · 0 评论 -
LeetCode#204: Count Primes
DescriptionCount the number of prime numbers less than a non-negative number, n.ExampleInput: 10Output: 4Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.Solution最直观暴力的...原创 2018-10-23 16:39:48 · 108 阅读 · 0 评论 -
LeetCode#697: Degree of an Array
DescriptionGiven a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.Your task is to find the smallest possible l...原创 2018-10-12 16:51:08 · 70 阅读 · 0 评论 -
LeetCode#695: Max Area of Island
DescriptionGiven a non-empty 2D array grid of 0’s and 1’s, an island is a group of 1’s (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the gri...原创 2018-10-12 16:32:51 · 78 阅读 · 0 评论 -
LeetCode#628: Maximum Product of Three Numbers
DescriptionGiven an integer array, find three numbers whose product is maximum and output the maximum product.ExampleInput: [1,2,3]Output: 6Input: [1,2,3,4]Output: 24NoteThe length of the g...原创 2018-10-11 11:59:16 · 107 阅读 · 0 评论 -
LeetCode#643: Maximum Average Subarray I
DescriptionGiven an array consisting of n integers, find the contiguous subarray of given length k that has the maximum average value. And you need to output the maximum average value.ExampleInput:...原创 2018-10-11 11:52:11 · 128 阅读 · 0 评论 -
LeetCode#122: Best Time to Buy and Sell Stock II
此题应该分清楚这两种情况:在一段时间内如果价格一路上升,则最早买、最晚卖时利润是最高的;如果中途有价格下跌而产生了低谷与高峰的情况,则在低谷买、高峰卖时利润最高。class Solution { public int maxProfit(int[] prices) { int maxProfit = 0; int lo = 0; int h...原创 2018-10-02 17:01:58 · 71 阅读 · 0 评论 -
LeetCode#717: 1-bit and 2-bit Characters
DescriptionWe have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11).Now given a string represented by sever...原创 2018-10-14 21:17:35 · 88 阅读 · 0 评论 -
LeetCode#242: Valid Anagram
DescriptionGiven two strings s and t , write a function to determine if t is an anagram of s.ExampleExample 1:Input: s = "anagram", t = "nagaram"Output: trueExample 2:Input: s = "rat", t = "...原创 2018-10-25 17:05:55 · 106 阅读 · 1 评论 -
LeetCode#136: Single Number
DescriptionGiven a non-empty array of integers, every element appears twice except for one. Find that single one.ExampleExample 1:Input: [2,2,1]Output: 1Example 2:Input: [4,1,2,1,2]Output: ...原创 2018-10-22 16:47:05 · 101 阅读 · 0 评论 -
LeetCode#665: Non-decreasing Array
DescriptionGiven an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element.We define an array is non-decreasing if array[i] <= array[i + 1] ...原创 2018-10-22 09:22:28 · 103 阅读 · 0 评论 -
LeetCode#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....原创 2018-10-10 15:31:03 · 104 阅读 · 0 评论 -
LeetCode#118: Pascal's Triangle
class Solution { public List<List<Integer>> generate(int numRows) { List<List<Integer>> listAll = new ArrayList<List<Integer>>(); if(numRows ...原创 2018-09-30 17:07:01 · 77 阅读 · 0 评论 -
LeetCode#88: Merge Sorted Array
class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { if (nums1 == null || nums1.length == 0 || nums2 == null || nums2.length == 0) return; ...原创 2018-09-30 17:06:11 · 103 阅读 · 0 评论 -
LeetCode#66: Plus One
class Solution { public int[] plusOne(int[] digits) { int n = digits.length - 1; digits[n]++; for(int i = n-1; i >= 0; i--) { if(digits[i+1] == 10) { digits[i+...原创 2018-09-30 17:05:22 · 110 阅读 · 0 评论