自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(132)
  • 收藏
  • 关注

转载 leetcode: palindrome-number

题目描述:在不使用额外的内存空间的条件下判断一个整数是否是回文提示:负整数可以是回文吗?(比如-1)如果你在考虑将数字转化为字符串的话,请注意一下不能使用额外空间的限制你可以将整数翻转。但是,如果你做过题目“Reverse Integer”,你会知道将整数翻转可能会出现溢出的情况,你...

2019-08-30 23:10:00 124

转载 leetcode: container-with-most-water

题目描述:给定n个非负整数a1,a2,…,an,其中每个数字表示坐标(i, ai)处的一个点。以(i,ai)和(i,0)(i=1,2,3...n)为端点画出n条直线。你可以从中选择两条线与x轴一起构成一个容器,最大的容器能装多少水?注意:你不能倾斜容器解题思路:此类求极值的问题一般都...

2019-08-29 22:57:00 140

转载 leetcode: next-permutation

题目描述:实现函数next permutation(下一个排列):将排列中的数字重新排列成字典序中的下一个更大的排列。将排列中的数字重新排列成字典序中的下一个更大的排列。如果不存在这样的排列,则将其排列为字典序最小的排列(升序排列)需要使用原地算法来解决这个问题,不能申请额外的内存空间...

2019-08-28 21:23:00 182

转载 leetcode: sort-colors

题目描述:现在有一个包含n个物体的数组,其中物体颜色为颜色为红色、白色或蓝色,请对这个数组进行排序,让相同颜色的物体相邻,颜色的顺序为红色,白色,蓝色。我们用 0, 1, 2分别代表颜色红,白,蓝注意:本题要求你不能使用排序库函数扩展:一个非常直接的解法是两步的计数排序的算法首先...

2019-08-26 23:02:00 157

转载 leetcode: remove-duplicates-from-sorted-array-ii

题目描述继续思考题目"Remove Duplicates":如果数组中元素最多允许重复两次呢?例如:给出有序数组 A =[1,1,1,2,2,3],你给出的函数应该返回length =5, A 变为[1,1,2,2,3]代码如下: public int removeDup...

2019-08-26 22:38:00 124

转载 leetcode: longest-consecutive-sequence

题目描述:给定一个无序的整数类型数组,求最长的连续元素序列的长度。例如:给出的数组为[100, 4, 200, 1, 3, 2],最长的连续元素序列为[1, 2, 3, 4]. 返回这个序列的长度:4你需要给出时间复杂度在O(n)之内的算法解题思路:这里利用 set 集合里不能...

2019-08-26 20:06:00 67

转载 leetcode:letter-combinations-of-a-phone-number

题目描述:给出一个仅包含数字的字符串,给出所有可能的字母组合。数字到字母的映射方式如下:(就像电话上数字和字母的映射一样)example:string "23"Output:["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]....

2019-08-25 22:18:00 91

转载 leetcode: generate-parentheses

题目描述:给出n对括号,请编写一个函数来生成所有的由n对括号组成的合法组合。例如,给出 n = 3,解集为:"((()))", "(()())", "(())()", "()(())", "()()()"解题思路:列举出所有可能的情况,必用递归来求解,这题也不例外我们采用 lef...

2019-08-25 21:39:00 88

转载 leetcode: search-for-a-range

题目描述:给出一个有序数组,请在数组中找出目标值的起始位置和结束位置你的算法的时间复杂度应该在O(log n)之内如果数组中不存在目标,返回[-1, -1].例如:给出的数组是[5, 7, 7, 8, 8, 10],目标值是8,返回[3, 4].解题思路:首先,对于时间复杂度...

2019-08-24 22:48:00 207

转载 leetcode: sudoku-solver

题目描述:请编写一个程序,给数独中的剩余的空格填写上数字空格用字符'.'表示解题思路:这一题与上一题大同小异只是小矩阵的求解变了代码如下:public class Solution { public void solveSudoku(char[][] board) {...

2019-08-23 22:27:00 145

转载 leetcode: valid-sudoku

题目描述:012345678根据数独的规则Sudoku Puzzles - The ...

2019-08-23 21:18:00 99

转载 leetcode: set-matrix-zeroes

题目描述:给定一个m*n的矩阵,如果有一个元素是0,就把该元素所在的行和列上的元素全置为0,要求使用原地算法。拓展:你的算法有使用额外的空间吗?一种比较直接的算法是利用O(m,n)的空间,但是这不是一个好的解法使用简单的改进可以在O(m+n)的空间解决这个问题,但是还不是最佳的解法...

2019-08-22 20:30:00 70

转载 leetcode: recover-binary-search-tree

题目描述:二叉搜索树(BST)中的两个节点被错误地交换了,请在不改变树的结构的情况下恢复这棵树。备注:用O(n)的空间解决这个问题的方法太暴力了,你能设计一个常数级空间复杂度的算法么?解题思路:这道题我想的有点复杂,我是想着怎么交换这两个节点实际上怎么做呢?只需要找到这两个出错...

2019-08-15 21:37:00 61

转载 leetcode: validate-binary-search-tree

题目描述:判断给出的二叉树是否是一个二叉搜索树(BST)二叉搜索树的定义如下:一个节点的左子树上节点的值都小于自身的节点值一个节点的右子树上节点的值都小于自身的节点值所有节点的左右子树都必须是二叉搜索树解题思路:解这道题之前我们应该弄清二叉树搜索的特性二叉树中序遍历的结果正好...

2019-08-15 21:14:00 74

转载 leetcode: symmetric-tree

题目描述:给定一棵二叉树,判断琪是否是自身的镜像(即:是否对称)解题思路:毫无疑问,这道题肯定用递归来求解比较方便考虑一下递归结束条件,基本上就可以写出来代码如下: public boolean isSymmetric(TreeNode root) { i...

2019-08-15 20:43:00 106

转载 leetcode: binary-tree-zigzag-level-order-traversal

题目描述给定一个二叉树,返回该二叉树的之字形层序遍历,(从左向右,下一层从右向左,一直这样交替)例如:给定的二叉树是{3,9,20,#,#,15,7},  5  / \ 4  8 / \ / \11 12 7 4该二叉树之字形层序遍历的结果是:[ [5] [8][4...

2019-08-14 22:16:00 97

转载 leetcode: maximum-depth-of-binary-tree

题目描述:求给定二叉树的最大深度,最大深度是指树的根结点到最远叶子结点的最长路径上结点的数量。解题思路:毫无疑问,递归来求解代码如下: public int maxDepth(TreeNode root) { // 递归结束条件 if(root ==...

2019-08-14 21:32:00 63

转载 leetcode: construct-binary-tree-from-inorder-and-postorder-traversal

题目描述:给出一棵树的中序遍历和后序遍历,请构造这颗二叉树注意:保证给出的树中不存在重复的节点Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assum...

2019-08-14 21:18:00 74

转载 leetcode: binary-tree-level-order-traversal-ii

题目描述:给定一个二叉树,返回该二叉树由底层到顶层的层序遍历,(从左向右,从叶子节点到根节点,一层一层的遍历)解题思路:本题的考察点是广度优先遍历,其次是集合向指定位置添加元素代码如下:public class Solution { public ArrayList<A...

2019-08-14 20:41:00 47

转载 leetcode: balanced-binary-tree

题目描述Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which ...

2019-08-13 21:07:00 78

转载 leetcode: path-sum-ii

题目描述:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the giv...

2019-08-13 20:46:00 92

转载 leetcode: path-sum

题目描述:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the giv...

2019-08-13 20:22:00 86

转载 leetcode: minimum-window-substring

题目描述:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S =...

2019-08-11 22:19:00 107

转载 leetcode: pascals-triangle-ii

题目描述:Given an index k, return the k th row of the Pascal's triangle.For example, given k = 3,Return[1,3,3,1].Note:Could you optimize your algo...

2019-08-11 20:50:00 96

转载 leetcode:pascals-triangle

题目描述:Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1],...

2019-08-11 19:39:00 84

转载 leetcode: jump-game-ii

题目描述:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents y...

2019-08-11 17:03:00 71

转载 leetcode: jump-game

题目描述:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents y...

2019-08-11 16:38:00 77

转载 leetcode: maximum-subarray

题目描述:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[−2,1,−3...

2019-08-11 16:04:00 85

转载 leetcode: gas-station

题目描述:沿着环形路线 有N个加油站,其中站i的气体量是气体 [i]。你有一辆带有无限油箱的汽车,从车站i到下一站(i + 1)需要花费 {i} 气。您可以在其中一个加油站开始使用空罐。如果您可以在电路周围行驶一次,则返回起始加油站的索引,否则返回-1。注意:解决方案保证是唯一的。...

2019-08-09 20:50:00 105

转载 leetcode: add-two-numbers

题目描述:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain ...

2019-08-09 20:15:00 91

转载 leetcode: reverse-nodes-in-k-group

题目描述:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of...

2019-08-07 23:48:00 107

转载 leetcode: swap-nodes-in-pairs

题目描述Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2-...

2019-08-07 23:27:00 73

转载 leetcode: merge-k-sorted-lists

题目描述:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.解题思路:这道的意思就是合并 k 个有序链表为 1 个链表合并两条链表想必大家...

2019-08-07 22:55:00 72

转载 leetcode: 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.For example,Given linked list: 1->2->3->4->5...

2019-08-07 22:41:00 90

转载 leetcode: reverse-linked-list-ii

题目描述:Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL, m = 2 and n...

2019-08-05 23:49:00 94

转载 leetcode: convert-sorted-list-to-binary-search-tree

题目描述:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.解题思路:首先理解题意,这道题的意思就是说将一个升序排列的...

2019-08-05 23:14:00 71

转载 leetcode: reorder-list

题目描述Given a singly linked list L: L 0→L 1→…→L n-1→L n,reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→…You must do this in-place without altering th...

2019-08-04 23:03:00 77

转载 leetcode:sort-list

题目描述:Sort a linked list in O(n log n) time using constant space complexity.解题思路:这道题的要求是在 O(n logn)的时间复杂度下,不适用额外的空间对链表重新排序哪些常见算法的复杂度满足题意呢?快排,归并...

2019-08-04 22:24:00 82

转载 leetcode: word-break

题目描述:Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary wo...

2019-08-02 22:49:00 64

转载 leetcode: interleaving-string

题目描述:Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 ="aabcc",s2 ="dbbca",When s3 ="aadbbcb...

2019-07-31 21:46:00 78

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除