
LeetCode
文章平均质量分 68
锤子剪子布
Improvise, Adapt, Overcome
展开
-
[LeetCode] 228. Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.Example 1:Input: [0,1,2,4,5,7]Output: ["0->2","4->5","7"]Explanation: 0,1,2 form a continuous range;4,5...原创 2020-03-18 11:29:29 · 133 阅读 · 0 评论 -
[LeetCode] 754. Reach a Number
You are standing at position0on an infinite number line. There is a goal at positiontarget.On each move, you can either go left or right. During then-th move (starting from 1), you takensteps....原创 2020-03-17 02:29:57 · 156 阅读 · 0 评论 -
[LeetCode] 830. Positions of Large Groups
In a string S of lowercase letters, these letters form consecutive groups of the same character.For example, a string like S = "abbxxxxzyy" has the groups "a", "bb", "xxxx", "z" and "yy".Call原创 2018-07-17 22:14:15 · 181 阅读 · 0 评论 -
[LeetCode] 141. Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list. * class ListNode { * int val; * ListNod...原创 2018-07-09 17:03:25 · 130 阅读 · 0 评论 -
[LeetCode] 692. Top K Frequent Words
Given a non-empty list of words, return the k most frequent elements.Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with the lowe...原创 2018-07-12 15:08:52 · 200 阅读 · 0 评论 -
[LeetCode] 5. Longest Palindromic Substring
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.Example 2:...原创 2018-07-06 01:08:07 · 148 阅读 · 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 / \...原创 2018-07-06 17:12:04 · 137 阅读 · 0 评论 -
[LeetCode] 566. Reshape the Matrix
In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data.You're given a matrix represented by a two-dimen...原创 2018-07-24 23:48:35 · 146 阅读 · 0 评论 -
[LeetCode] 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 without using ...原创 2018-07-07 14:51:30 · 202 阅读 · 0 评论 -
[LeetCode] 215. Kth Largest Element in an Array
题目:实现思路1:对数组升序排序,index=n-k的元素就是最终结果(n是数组长度)。class Solution { public int findKthLargest(int[] nums, int k) { if (nums == null) throw new IllegalArgumentException("argument is null"); ...原创 2018-07-14 02:11:39 · 433 阅读 · 0 评论 -
[LeetCode] 6. ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I I G...原创 2018-07-14 16:17:15 · 137 阅读 · 0 评论 -
[LeetCode] 344. Reverse String
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".题目:输入一个字符串,返回其反转字符串。实现思路1:最直接的办法是用StringBuilder的reverse方法。class Solution { p...原创 2018-07-15 11:49:26 · 162 阅读 · 0 评论 -
[LeetCode] 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]Output: ...原创 2018-07-30 00:08:26 · 495 阅读 · 0 评论 -
[LeetCode] 242. Valid Anagram
Given two strings s and t , write a function to determine if t is an anagram of s.Example 1:Input: s = "anagram", t = "nagaram"Output: trueExample 2:Input: s = "rat", t = "car"Output: falseNote:Yo...原创 2018-07-04 14:53:28 · 218 阅读 · 0 评论 -
[LeetCode] 387. First Unique Character in a String
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode"return 0.s = "loveleetcode",return 2.Note: You may assume ...原创 2018-07-11 12:08:29 · 192 阅读 · 0 评论 -
[LeetCode] 520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases holds:All letters in this word...原创 2018-06-21 18:56:41 · 103 阅读 · 0 评论 -
[LeetCode] 1. Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same el...原创 2018-06-14 10:55:53 · 109 阅读 · 0 评论 -
[LeetCode] 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 return i...原创 2018-06-14 11:51:54 · 116 阅读 · 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 / / \ 4 5 6...原创 2018-06-22 16:44:28 · 124 阅读 · 0 评论 -
[LeetCode] 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.Exam...原创 2018-06-15 00:56:00 · 125 阅读 · 0 评论 -
[LeetCode] 3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with the l...原创 2018-06-16 15:08:42 · 98 阅读 · 0 评论 -
[LeetCode] 118. Pascal's Triangle
Given a non-negative integer numRows, generate the first numRows of Pascal's triangle.In Pascal's triangle, each number is the sum of the two numbers directly above it.Example:Input: 5Output:[ ...原创 2018-06-24 12:34:22 · 183 阅读 · 0 评论 -
[LeetCode] 179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.Example 1:Input: [10,2]Output: "210"Example 2:Input: [3,30,34,5,9]Output: "9534330"Note: The result may be ...原创 2018-06-29 13:14:28 · 169 阅读 · 0 评论 -
[LeetCode] 739. Daily Temperatures
Given a list of daily temperatures, produce a list that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this ...原创 2018-06-26 12:52:13 · 142 阅读 · 0 评论 -
[LeetCode] 4. Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 = [1, 3]nums2...原创 2018-06-20 10:06:57 · 139 阅读 · 0 评论 -
[LeetCode] 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 represented by a...原创 2018-07-02 19:26:02 · 139 阅读 · 0 评论 -
[LeetCode] 49. Group Anagrams
Given an array of strings, group anagrams together.Example:Input: ["eat", "tea", "tan", "ate", "nat", "bat"],Output:[ ["ate","eat","tea"], ["nat",&原创 2018-06-28 11:11:11 · 164 阅读 · 0 评论 -
[LeetCode] 868. Transpose Matrix
Given a matrix A, return the transpose of A.The transpose of a matrix is the matrix flipped over it's main diagonal, switching the row and column indices of the matrix.Example 1:Input: [[1,2,3],[4,5,6...原创 2018-07-10 15:05:21 · 183 阅读 · 0 评论 -
[LeetCode] 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 children.Ex...原创 2018-07-03 22:58:09 · 145 阅读 · 0 评论 -
[LeetCode] 347. Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number of unique elemen...原创 2018-06-21 15:11:03 · 136 阅读 · 0 评论