- 博客(30)
- 收藏
- 关注
原创 [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
132
原创 [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
155
原创 [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
493
原创 [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
原创 [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
180
原创 [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
161
原创 [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
136
原创 [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
432
原创 [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
197
原创 [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
原创 [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
182
原创 [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
129
原创 [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
原创 [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
原创 [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
原创 [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
原创 [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
143
原创 [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
138
原创 [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
168
原创 [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
162
原创 [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
原创 [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
182
原创 [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
原创 [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
原创 [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
原创 [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
138
原创 [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
97
原创 [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
原创 [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
原创 [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
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人