LeetCode
水木今山
什么都没有
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode#530: Minimum Absolute Difference in BST
Description Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes. Example Input: 1 \ 3 / 2 Output: 1 Explanat...原创 2019-01-23 11:52:54 · 205 阅读 · 0 评论 -
LeetCode#190: Reverse Bits
Description Reverse bits of a given 32 bits unsigned integer. Example Input: 43261596 Output: 964176192 Explanation: 43261596 represented in binary as 00000010100101000001111010011100, r...原创 2018-11-19 09:03:56 · 150 阅读 · 1 评论 -
LeetCode#784: Letter Case Permutation
Description Given 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. Example Input: S...原创 2018-11-16 12:12:22 · 306 阅读 · 0 评论 -
LeetCode#859: Buddy Strings
Description Given 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. Example Input: A = "ab", B = "ba" Output: true Input: ...原创 2018-11-12 12:23:02 · 210 阅读 · 0 评论 -
LeetCode#367: Valid Perfect Square
Description Given a positive integer num, write a function which returns True if num is a perfect square else False. Example Input: 16 Output: true Input: 14 Output: false Solution 二分查找法 最容易想到的一种方法便...原创 2018-11-13 17:11:50 · 322 阅读 · 0 评论 -
LeetCode#67: Add Binary
Description Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only characters 1 or 0. Example Input: a = "11", b = "1" Output: "100" ...原创 2018-11-07 17:06:56 · 136 阅读 · 0 评论 -
LeetCode#696: Count Binary Substrings
Description Give 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 · 340 阅读 · 0 评论 -
LeetCode#686: Repeated String Match
Description Given 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 · 363 阅读 · 0 评论 -
LeetCode#234: Palindrome Linked List
Description Given a singly linked list, determine if it is a palindrome. class ListNode { int val; ListNode next; ListNode(int x) { val = x; } } Example Example 1: Input: 1->2 Output:...原创 2018-11-04 10:35:43 · 166 阅读 · 0 评论 -
LeetCode#680: Valid Palindrome II
Description Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome. Example Input: "aba" Output: True Input: "abca" Output: True Explanation: You...原创 2018-11-09 17:05:05 · 183 阅读 · 0 评论 -
LeetCode#21: Merge Two Sorted Lists
Description Merge 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. Example Example: Input: 1->2->4, 1->...原创 2018-11-01 11:49:51 · 192 阅读 · 0 评论 -
LeetCode#897: Increasing Order Search Tree
Description Given 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. Example Example 1: ...原创 2018-11-21 16:55:15 · 207 阅读 · 0 评论 -
LeetCde#198: House Robber
Description You 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 · 232 阅读 · 0 评论 -
树的前中后层序遍历(递归与非递归方式)
Description 此题与429、589题型类似,因此放在一起总结。 () 对于上图要求求出前序遍历、后序遍历和层级遍历的结果。 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 · 364 阅读 · 0 评论 -
LeetCode#543: Diameter of Binary Tree
Description 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 ...原创 2019-01-20 11:40:58 · 217 阅读 · 0 评论 -
LeeCode#172: Factorial Trailing Zeroes
Description Given an integer n, return the number of trailing zeroes in n!. Example Example 1: Input: 3 Output: 0 Explanation: 3! = 6, no trailing zero. Example 2: Input: 5 Output: 1 Explanation: 5!...原创 2019-01-24 22:21:48 · 244 阅读 · 0 评论 -
LeetCode#168: Excel Sheet Column Title
Description Given 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 · 229 阅读 · 0 评论 -
LeetCode#110: Balanced Binary Tree
Description 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 n...原创 2018-11-27 11:58:26 · 240 阅读 · 0 评论 -
LeetCode: Symmetric Tree
Description Given 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 · 164 阅读 · 0 评论 -
LeetCode#108: Convert Sorted Array to Binary Search Tree
Description 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 d...原创 2018-11-23 11:51:42 · 157 阅读 · 0 评论 -
LeetCode#405: Convert a Number to Hexadecimal
Description Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used. Example Input: 26 Output: "1a" Input: -1 Output: "ffffffff" No...原创 2018-11-18 11:59:59 · 197 阅读 · 0 评论 -
LeetCode#476: Number Complement
Description Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation. Note The given integer is guaranteed to fit within the ra...原创 2018-11-18 11:48:06 · 271 阅读 · 1 评论 -
LeetCode#703: Kth Largest Element in a Stream
Description Design 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 · 551 阅读 · 0 评论 -
LeetCode#496: Next Greater Element I
Description You 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 · 184 阅读 · 0 评论 -
LeetCode#594: LongestHarmoniousSubsequence
Description We 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 · 173 阅读 · 0 评论 -
LeetCode#690: Employee Importance
Description You 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 · 182 阅读 · 0 评论 -
LeetCode#204: Count Primes
Description Count the number of prime numbers less than a non-negative number, n. Example Input: 10 Output: 4 Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7. Solution 最直观暴力的...原创 2018-10-23 16:39:48 · 162 阅读 · 0 评论 -
LeetCode#697: Degree of an Array
Description Given 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 · 143 阅读 · 0 评论 -
LeetCode#695: Max Area of Island
Description Given 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 · 150 阅读 · 0 评论 -
LeetCode#628: Maximum Product of Three Numbers
Description Given an integer array, find three numbers whose product is maximum and output the maximum product. Example Input: [1,2,3] Output: 6 Input: [1,2,3,4] Output: 24 Note The length of the g...原创 2018-10-11 11:59:16 · 182 阅读 · 0 评论 -
LeetCode#643: Maximum Average Subarray I
Description Given 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. Example Input:...原创 2018-10-11 11:52:11 · 232 阅读 · 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 · 120 阅读 · 0 评论 -
LeetCode#717: 1-bit and 2-bit Characters
Description We 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 · 151 阅读 · 0 评论 -
LeetCode#242: Valid Anagram
Description Given two strings s and t , write a function to determine if t is an anagram of s. Example Example 1: Input: s = "anagram", t = "nagaram" Output: true Example 2: Input: s = "rat", t = "...原创 2018-10-25 17:05:55 · 176 阅读 · 1 评论 -
LeetCode#136: Single Number
Description Given a non-empty array of integers, every element appears twice except for one. Find that single one. Example Example 1: Input: [2,2,1] Output: 1 Example 2: Input: [4,1,2,1,2] Output: ...原创 2018-10-22 16:47:05 · 172 阅读 · 0 评论 -
LeetCode#665: Non-decreasing Array
Description Given 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 · 151 阅读 · 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 · 145 阅读 · 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 · 149 阅读 · 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 · 187 阅读 · 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 · 174 阅读 · 0 评论
分享