
leetcode
文章平均质量分 68
徐不依
这个作者很懒,什么都没留下…
展开
-
70. Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a positi原创 2017-09-20 22:06:06 · 266 阅读 · 0 评论 -
5. Longest Palindromic Substring
问题描述:寻找字符串的最长回文子序列。Example 1:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.Example 2:Input: "cbbd"Output: "bb"Soulution 1 (中心展开):回文序列从中心字符向两边扩展两边元素相同,需要考虑奇数个和偶数个的情况。注意...原创 2018-11-20 20:36:17 · 120 阅读 · 0 评论 -
739. Daily Temperatures
Given a list of daily temperatures T, return a list such 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 wh...原创 2018-11-24 16:42:53 · 157 阅读 · 0 评论 -
633. Sum of Square Numbers
Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c.Example 1:Input: 5Output: TrueExplanation: 1 * 1 + 2 * 2 = 5 Example 2:...原创 2018-11-24 22:32:10 · 197 阅读 · 0 评论 -
167. Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers ...原创 2018-11-24 22:36:48 · 133 阅读 · 0 评论 -
4. Median of Two Sorted Arrays
问题描述:两个有序数组,输出他们的中位数。The overall run time complexity should be O(log (m+n)).Example 1:nums1 = [1, 3]nums2 = [2]The median is 2.0Example 2:nums1 = [1, 2]nums2 = [3, 4]The median is (2 ...原创 2018-11-20 14:42:22 · 108 阅读 · 0 评论 -
122. Best Time to Buy and Sell Stock II (Array)
##### 题目描述:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like ...原创 2019-01-03 20:36:47 · 121 阅读 · 0 评论 -
63. Unique Paths II (Array, DP)
##### 题目描述:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to...原创 2019-01-03 21:52:27 · 110 阅读 · 0 评论 -
19. Remove Nth Node From End of List (双指针)
Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, t...原创 2019-01-10 15:56:29 · 720 阅读 · 0 评论 -
31. Next Permutation
题目Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest poss原创 2017-10-21 19:49:11 · 274 阅读 · 0 评论 -
14. Longest Common Prefix
题目:Write a function to find the longest common prefix string amongst an array of strings.思路:先找到所有字符串最小长度,然后在这个范围内进行比较。每次从strs[0]中取一个char,和后面的字符串进行比较。public String longestCommonPrefix(String[]原创 2017-10-21 11:48:00 · 505 阅读 · 0 评论 -
75. Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers原创 2017-09-20 22:54:42 · 184 阅读 · 0 评论 -
48. Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the input 2D matrix d原创 2017-10-17 20:06:25 · 182 阅读 · 0 评论 -
73. Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.这道题难点在于不能用额外空间,直接根据是否为零的状态改变原矩阵会覆盖没有遍历到的矩阵数值。如果用额外空间的话就先判断一遍用新的相同大小的矩阵存储状态,再根据那个矩阵改变出初始矩阵的值。不能用额外空间的话原创 2017-10-17 20:47:34 · 188 阅读 · 0 评论 -
74. Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each原创 2017-10-18 20:02:06 · 204 阅读 · 0 评论 -
79. Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically n原创 2017-10-18 21:02:54 · 148 阅读 · 0 评论 -
94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,3,2]. 我的做法:用的是递归,定义doTraversa原创 2017-10-10 14:54:32 · 163 阅读 · 0 评论 -
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,转载 2017-10-10 16:53:45 · 172 阅读 · 0 评论 -
33. Search in Rotated Sorted Array && 81. Search in Rotated Sorted Array II
题目:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become4 5 6 7 0 1 2).You are given a target value to search. If foun转载 2017-10-21 10:44:15 · 185 阅读 · 0 评论 -
78. Subset && 90.Subset 2 (Array, DFS)
##### 78. Subsets 求不含重复数字的数组的子集Given a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: num...原创 2019-01-06 00:35:26 · 236 阅读 · 0 评论 -
46 Permutations && 47 Permutation II (Array, DFS)
78 Permutation IGiven a collection of numbers, return all possible permutations.For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].和上次...原创 2019-01-06 22:37:00 · 163 阅读 · 0 评论 -
121. Best Time to Buy and Sell Stock(Array)
##### 题目描述:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share o...原创 2019-01-02 20:45:07 · 113 阅读 · 0 评论 -
23. Merge k Sorted Lists (Divide and conquer, Linked List) 以及java匿名内部类
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[ 1->4->5, 1->3->4, 2->6]Output: 1->1->2->3->4-...原创 2019-01-16 17:05:40 · 238 阅读 · 0 评论 -
20. Valid Parentheses && 32. Longest Valid Parentheses (String, Stack, DP)
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of b...原创 2019-01-23 11:05:17 · 311 阅读 · 0 评论 -
130. Surrounded Regions (DFS)
经过一个月的倦怠期,我徐汉三又回来啦!FLAG每天至少一道题坚持到秋招offer!!!今天的题目是DFS思想。https://leetcode.com/problems/surrounded-regions/Given a 2D board containing'X'and'O'(the letter O), capture all regions surrounded by'X...原创 2019-04-16 22:33:36 · 202 阅读 · 0 评论 -
24. Swap Nodes in Pairs
题目要将相邻两个节点交换但是不能只交换数值。1. 我的方法 循环 1)需要注意判断是否是null,凡是要调用next就要注意了! 2)注意交换两个节点之后,node指向的下一个并不是当前后面链表的头(因为后面也要交换),所以应该判断下后面会不会继续交换,如果是的话就要指向下下个,不然就直接指向下一个。class Solution { public ListNode ...原创 2019-04-22 21:54:26 · 118 阅读 · 0 评论 -
234. Palindrome Linked List
判断是否是回文链表,尽量在O(n)时间复杂度。思路:快慢指针,慢指针指向的前面一部分序列倒序(从后向前指)。当快指针到头时刚好慢指针把前一半倒序。此时Pre指针指向的是前面一般=半链表的倒叙的头, 慢指针指向后面一半的头。注意如果循环结束时快指针不是空则说明链表节点数是奇数个,那slow指针要向前移一个。还有循环判断条件应该是next 和next.next还有要先更改快指针,否...原创 2019-04-23 23:40:57 · 132 阅读 · 0 评论 -
29. Divide Two Integers
要求不用乘除取余运算计算整形向零取整除法。Example 1:Input: dividend = 10, divisor = 3Output: 3Example 2:Input: dividend = 7, divisor = -3Output: -21. 不能超时,所以要用二分法来加速2. 边界条件。注意不要超过32位int的范围。特别恶心的:因为-2147483...原创 2019-04-25 13:24:06 · 179 阅读 · 0 评论 -
LeetCode数组类知识点&题型总结
参考博主charlotte的总结,记录自己的刷题过程。她真的很棒~https://github.com/huxiaoman7/leetcodebookhttps://mp.weixin.qq.com/s?__biz=MzI0OTQwMTA5Ng==&mid=2247483819&idx=1&sn=071731261441f702f429ae9fc1b98b84&...原创 2019-05-23 14:19:55 · 2388 阅读 · 0 评论 -
279. Perfect Squares (DFS, DP)
https://leetcode.com/problems/perfect-squares/Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.Example 1:Input: n = 12...原创 2019-06-25 22:38:22 · 207 阅读 · 0 评论 -
120. Triangle (DP)
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5...原创 2019-01-15 22:38:36 · 141 阅读 · 0 评论 -
343. Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.Example 1:Input: 2Output: 1...原创 2019-01-13 21:12:21 · 118 阅读 · 0 评论 -
119. Pascal's Triangle II (Array)
##### 题目描述:Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.Note that the row index starts from 0.Example:Input: 3Output: [1,3,3,1]##### 分析:...原创 2019-01-02 21:52:24 · 128 阅读 · 0 评论 -
49. Group Anagrams (String, Map)
Given an array of strings, group anagrams together.Example:Input: ["eat", "tea", "tan", "ate", "nat", "bat"],Output:[ ["ate","eat","tea"], ["nat"原创 2019-01-12 15:30:16 · 167 阅读 · 0 评论 -
139. Word Break (DP)
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.Note:The ...原创 2019-01-12 19:34:22 · 176 阅读 · 0 评论 -
96. Unique Binary Search Trees && 95. Unique Binary Search Trees II(DP)
96. Unique Binary Search TreesGiven n, how many structurally unique BST's (binary search trees) that store values 1 ... n?Example:Input: 3Output: 5Explanation:Given n = 3, there are a total ...原创 2019-01-12 21:15:35 · 1398 阅读 · 0 评论 -
39. Combination Sum 40 Combination Sum 2(Array, DFS)
39. Combination SumGiven a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to tar...原创 2019-01-07 21:56:02 · 164 阅读 · 0 评论 -
22. Generate Parentheses (DFS, String)
22. Generate ParenthesesGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()()...原创 2019-01-07 23:06:24 · 143 阅读 · 0 评论 -
72. Edit Distance (DP)
Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.You have the following 3 operations permitted on a word:Insert a character Delete a chara...原创 2019-01-13 12:50:26 · 286 阅读 · 0 评论 -
17. Letter Combinations of a Phone Number (DFS, String)
17. Letter Combinations of a Phone NumberGiven a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters ...原创 2019-01-08 10:25:31 · 159 阅读 · 0 评论