
LeetCode
咸鱼塘塘主
我只是不想我的未来黯淡无光
展开
-
LeetCode-Java-637. Average of Levels in Binary Tree
题目Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.Example 1:Input: 3 / \ 9 20 / \ 15 7Output: [3, 14.5, 11]Explanati...原创 2018-09-27 16:28:13 · 333 阅读 · 0 评论 -
LeetCode-Java-344. Reverse String
题目Write a function that takes a string as input and returns the string reversed.Example 1:Input: "hello"Output: "olleh"Example 2:Input: "A man, a plan, a canal: Panama"Output: "amanaP :la...原创 2018-08-19 14:18:55 · 316 阅读 · 0 评论 -
LeetCode-Java-766. Toeplitz Matrix
题目A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element.Now given an M x N matrix, return True if and only if the matrix is Toeplitz.Example 1:Input:mat...原创 2018-08-26 10:31:26 · 253 阅读 · 0 评论 -
LeetCode-Java-872. Leaf-Similar Trees
题目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 i...原创 2018-08-22 12:58:34 · 227 阅读 · 2 评论 -
LeetCode-Java-557. Reverse Words in a String III
题目Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode conte...原创 2018-08-19 13:46:10 · 325 阅读 · 0 评论 -
LeetCode-Java-821. Shortest Distance to a Character
题目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,...原创 2018-08-19 13:15:31 · 326 阅读 · 0 评论 -
LeetCode-Java-884. Uncommon Words from Two Sentences
题目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 th...原创 2018-08-18 10:22:05 · 484 阅读 · 0 评论 -
LeetCode-Java-811. Subdomain Visit Count
题目A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com", and at the lowest level, "discuss.leetcod...原创 2018-08-18 09:44:27 · 337 阅读 · 0 评论 -
LeetCode-Java-876. Middle of the Linked List
题目Given a non-empty, singly linked list with head node head, return a middle node of linked list.If there are two middle nodes, return the second middle node.Example 1:Input: [1,2,3,4,5]O...原创 2018-08-02 10:02:40 · 422 阅读 · 0 评论 -
LeetCode-Java-500. Keyboard Row
题目Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.American keyboardrow1:qwertyuioprow2:asdfghjk...原创 2018-07-22 16:42:25 · 265 阅读 · 0 评论 -
LeetCode-Java-476. Number Complement
题目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 range o...原创 2018-07-22 15:53:45 · 171 阅读 · 0 评论 -
LeetCode-Java-868. Binary Gap
题目Given a positive integer N, find and return the longest distance between two consecutive 1's in the binary representation of N.If there aren't two consecutive 1's, return 0.Example 1:Inp...原创 2018-07-22 15:32:18 · 342 阅读 · 0 评论 -
LeetCode-SQL-620. Not Boring Movies
题目X city opened a new cinema, many people would like to go to this cinema. The cinema also gives out a poster indicating the movies’ ratings and descriptions.Please write a SQL query to output mo...原创 2018-08-19 14:32:45 · 225 阅读 · 0 评论 -
LeetCode-Java-559. Maximum Depth of N-ary Tree
题目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-08-19 15:30:30 · 409 阅读 · 0 评论 -
LeetCode-Java-136. Single Number
题目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 with...原创 2018-08-19 16:56:23 · 296 阅读 · 0 评论 -
LeetCode-Java-496. Next Greater Element I
题目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 of nums2...原创 2018-09-27 14:31:58 · 307 阅读 · 0 评论 -
LeetCode-Java-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 c...原创 2018-09-14 23:34:19 · 186 阅读 · 0 评论 -
LeetCode-Java-897. Increasing Order Search Tree
题目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 1:Input: [5,3,6,2,...原创 2018-09-17 20:34:22 · 660 阅读 · 2 评论 -
LeetCode-Java-762. Prime Number of Set Bits in Binary Representation
题目Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary representation.(Recall that the number of set bits an integ...原创 2018-09-17 19:28:19 · 240 阅读 · 0 评论 -
LeetCode-Java-707. Design Linked List
题目Design your implementation of the linked list. You can choose to use the singly linked list or the doubly linked list. A node in a singly linked list should have two attributes: val and next. val...原创 2018-09-06 23:50:53 · 1014 阅读 · 0 评论 -
LeetCode-Java-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. Retur...原创 2018-09-03 23:42:21 · 189 阅读 · 0 评论 -
LeetCode-Java-492. Construct the Rectangle
题目For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose le...原创 2018-09-06 00:32:07 · 181 阅读 · 0 评论 -
LeetCode-Java-697. Degree of an Array
题目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 length...原创 2018-09-05 13:18:34 · 268 阅读 · 0 评论 -
LeetCode-Java-896. Monotonic Array
题目An array is monotonic if it is either monotone increasing or monotone decreasing.An array A is monotone increasing if for all i <= j, A[i] <= A[j]. An array A is monotone decreasing if ...原创 2018-09-03 00:34:12 · 461 阅读 · 0 评论 -
LeetCode-Java-893. Groups of Special-Equivalent Strings
题目You are given an array A of strings.Two strings S and T are special-equivalent if after any number of moves, S == T.A move consists of choosing two indices i and j with i % 2 == j % 2, and s...原创 2018-08-29 16:26:46 · 589 阅读 · 0 评论 -
LeetCode-Java-575. Distribute Candies
题目Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need to distribute...原创 2018-08-29 12:19:33 · 207 阅读 · 0 评论 -
LeetCode-Java-806. Number of Lines To Write String
题目We are to write the letters of a given string S, from left to right into lines. Each line has maximum width 100 units, and if writing a letter would cause the width of the line to exceed 100 uni...原创 2018-07-22 14:31:46 · 197 阅读 · 0 评论 -
LeetCode-Java-561. Array Partition I
题目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 a...原创 2018-07-20 20:17:14 · 225 阅读 · 0 评论 -
LeetCode-Java-13. Roman to Integer
题目Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2018-07-18 22:49:52 · 154 阅读 · 0 评论 -
LeetCode-Java-657. Judge Route Circle
题目Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place.The move sequence is represen...原创 2018-07-18 20:05:47 · 244 阅读 · 0 评论 -
LeetCode-Java-728. Self Dividing Numbers
题目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-d...原创 2018-07-18 20:04:26 · 195 阅读 · 0 评论 -
LeetCode-Java-771. Jewels and Stones
题目You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of t...原创 2018-07-18 20:02:42 · 350 阅读 · 0 评论 -
LeetCode-Java-804. Unique Morse Code Words
题目International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ".-", "b" maps to "-...", "c" maps to "-.-.", and so原创 2018-07-18 19:59:50 · 361 阅读 · 0 评论 -
LeetCode-Java-852. Peak Index in a Mountain Array
题目Let's call an array A a mountain if the following properties hold:A.length >= 3There exists some 0 < i < A.length - 1 such that A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] &...原创 2018-07-18 19:47:55 · 204 阅读 · 0 评论 -
LeetCode-Java-405. Convert a Number to Hexadecimal
题目Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.Note:All letters in hexadecimal (a-f) must be in lowercase.The hexad...原创 2018-07-11 21:25:43 · 300 阅读 · 0 评论 -
LeetCode-Java-2. Add Two Numbers
题目You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and re...原创 2018-07-11 19:39:23 · 351 阅读 · 0 评论 -
LeetCode-Java-1. Two Sum
题目Given an array of integers, return indices of the two numbers such that they add up to a specific target.给一个int型的数组,返回两个数的索引,使它们相加等于一个特定的整数You may assume that each input would have exactly one...原创 2018-07-11 19:15:10 · 248 阅读 · 0 评论 -
LeetCode-Java-238. Product of Array Except Self
题目Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].给一个n个int的数组nums,其中n>1,返回一个数组,使得...原创 2018-07-11 08:09:28 · 216 阅读 · 0 评论 -
LeetCode-Java-27. Remove Element
题目Given an array nums and a value val, remove all instances of that value in-place and return the new length.给定一个数组num和一个值,在这个数组中删除这个值得全部实例并且返回新的长度Do not allocate extra space for another array, ...原创 2018-07-10 20:43:31 · 178 阅读 · 0 评论 -
LeetCode-Java-14. Longest Common Prefix
题目Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string "".Example 1:Input: ["flower","flow","flight"]Ou...原创 2018-07-19 20:58:34 · 205 阅读 · 0 评论