
leetcode
每天开心成为别人的望尘莫及
这个作者很懒,什么都没留下…
展开
-
15. 3Sum ***
题目:Given array nums = [-1, 0, 1, 2, -1, -4],A solution set is:[ [-1, 0, 1], [-1, -1, 2]]从数组中找三个不能重复的数字,和为0。三个数从小到大排列思路:(1)深搜,然后结果(三个数)从小到大排列,但是应该会超时(2)先把原数组从小到大排列,再深搜,也会超时吧(3)第三种方法:...原创 2019-04-16 17:30:20 · 94 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters 没有重复字符的最长子串
hashtable题目描述:Given a string, find the length of thelongest substringwithout repeating characters.Example 1:Input: "abcabcbb"Output: 3 Explanation: The answer is "abc", with the length of...原创 2019-05-29 17:17:19 · 134 阅读 · 0 评论 -
49. Group Anagrams
属于hashTable题目描述:Given an array of strings, group anagrams together.Example:Input: ["eat", "tea", "tan", "ate", "nat", "bat"],Output:[ ["ate","eat","tea"], ["nat","tan"], ["bat"]]No...原创 2019-05-29 16:44:41 · 189 阅读 · 0 评论 -
347. Top K Frequent Elements
题目:Given a non-empty array of integers, return thekmost frequent elements.Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2]Example 2:Input: nums = [1], k = 1Output: [1]Note:...原创 2019-05-29 15:54:18 · 151 阅读 · 0 评论 -
96. Binary Tree Inorder Traversal
题目描述:Given a binary tree, return theinordertraversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,3,2]Follow up:Recursive solution is trivial, ...原创 2019-05-29 15:14:36 · 144 阅读 · 0 评论 -
142. Linked List Cycle II 找到环的起始位置
Example 1:Input: head = [3,2,0,-4], pos = 1Output: tail connects to node index 1Explanation: There is a cycle in the linked list, where tail connects to the second node.Example 2:Input: h...原创 2019-05-30 18:44:07 · 225 阅读 · 0 评论 -
148. Sort List 给链表排序
题目描述:Sort a linked list inO(nlogn) time using constant space complexity.Example 1:Input: 4->2->1->3Output: 1->2->3->4Example 2:Input: -1->5->3->4->0Outp...原创 2019-05-30 15:56:09 · 359 阅读 · 0 评论 -
234. Palindrome Linked List
题目描述:Given a singly linked list, determine if it is a palindrome.Example 1:Input: 1->2Output: falseExample 2:Input: 1->2->2->1Output: trueFollow up:Could you do it in O(n)...原创 2019-05-30 14:43:25 · 175 阅读 · 0 评论 -
739. Daily Temperatures
给定一个每日温度的数组,生成一个数组,要求:对于新数组的每个元素,是你需要等待更暖和的天数。如果接下去没有更暖的天了,那就用0替代。比如,给定数组temperatures = [73, 74, 75, 71, 69, 72, 76, 73], 你需要输出[1, 1, 4, 2, 1, 1, 0, 0].原数组第1天是73度,第2天74度是更暖和的一天,所以新数组第1元素就是1.注:数...原创 2019-05-27 15:16:41 · 171 阅读 · 0 评论 -
438. Find All Anagrams in a String 找出字符串中所有的变位词
Given a stringsand anon-emptystringp, find all the start indices ofp's anagrams ins.Strings consists of lowercase English letters only and the length of both stringssandpwill not be large...原创 2019-05-27 11:43:36 · 160 阅读 · 0 评论 -
31. Next Permutation 下一个排列
题目描述;实现下一个排列,它将数字重新排列到字典上的下一个更大的数字排列。如果这种安排不可能,则必须将其重新排列为尽可能低的顺序(即按升序排序)。替换必须就地,并且仅使用恒定的额外内存。这里有些例子。输入位于左侧列中,其相应的输出位于右侧列中。1,2,3 → 1,3,23,2,1 → 1,2,31,1,5 → 1,5,1思路:第一步:从后往前遍历,遇到后面的数字大...原创 2019-04-15 10:23:45 · 174 阅读 · 0 评论 -
LeetCode 79
class Solution { public boolean exist(char[][] board, String word) { int hang = board.length; int lie = board[0].length; int sum = 0;//记录有没有word存在,也可以记录存在的个数 //设置一...原创 2019-04-15 09:46:11 · 255 阅读 · 0 评论 -
组合的算法题目
Leetcode39.组合总和参考:https://blog.youkuaiyun.com/love905661433/article/details/85250243题目给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。candidates 中的数字可以无限制重复被选取。说明:...原创 2019-07-12 16:42:16 · 391 阅读 · 0 评论