自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 每日一恋 - LeetCode 102 & 107. 二叉树的层次遍历

102. 二叉树的层次遍历解法一用队列实现 步骤:当队列不为空时,计算队列中元素的个数,作为本层循环的次数。依次取出队列中指定个数的节点,加入到subList中,同时将其左右孩子加入到队列中。重复1、2直到队列里没有元素。 public List<List<Integer>> levelOrder(TreeNode root) { Q...

2018-08-18 13:34:32 198

原创 每日一恋 - LeetCode 144 & 94 & 145. 二叉树的前序遍历、中序遍历、后序遍历

144. 二叉树的前序遍历通常,实现二叉树的前序(preorder)、中序(inorder)、后序(postorder)遍历有两个常用的方法:一是递归(recursive),二是使用栈实现的迭代版本(stack+iterative)。这两种方法都是O(n)的空间复杂度(递归本身占用stack空间或者用户自定义的stack)。解法一迭代版,用栈存放遍历的节点,注意是按照访问节点,压入右节...

2018-08-18 12:39:21 179

原创 每日一恋 - LeetCode 71. Simplify Path(简化路径)

题目描述给定一个文档 (Unix-style) 的完全路径,请进行路径简化。例如,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"边界情况:你是否考虑了 路径 = “/../” 的情况? 在这种情况下,你需返回 “/” 。此外,路径中也可能包含多个斜杠 ‘/’ ,如 “/home//...

2018-08-17 16:01:34 217

原创 每日一恋 - LeetCode 20.有效的括号 & 150. 逆波兰表达式求值

20. 有效的括号给定一个只包括 ‘(‘,’)’,’{‘,’}’,’[‘,’]’ 的字符串,判断字符串是否有效。有效字符串需满足:左括号必须用相同类型的右括号闭合。左括号必须以正确的顺序闭合。注意空字符串可被认为是有效字符串。分析每个右括号与最近的左括号匹配,所以这道题可以用栈结构来解决。每次都将左括号压入栈,一旦遇到右括号,从栈中弹出一个左括号判断是否与之匹配,匹...

2018-08-17 15:53:28 213

原创 每日一恋 - LeetCode 143. Reorder List(重排链表)

题目描述给定一个单链表 L:L0→L1→…→Ln-1→Ln , 将其重新排列后变为: L0→Ln→L1→Ln-1→L2→Ln-2→…你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。示例 1:给定链表 1->2->3->4, 重新排列为 1->4->2->3.示例 2:给定链表 1->2->3->4...

2018-08-17 15:16:24 186

原创 每日一恋 - LeetCode 61. Rotate List(旋转链表)

给定一个链表,旋转链表,将链表每个节点向右移动 k 个位置,其中 k 是非负数。示例 1:输入: 1->2->3->4->5->NULL, k = 2输出: 4->5->1->2->3->NULL解释:向右旋转 1 步: 5->1-&g

2018-08-17 14:11:27 122

原创 每日一恋 - LeetCode 24 & 25. 交换链表中的节点

24. 两两交换链表中的节点给定一个链表,两两交换其中相邻的节点,并返回交换后的链表。示例:给定 1->2->3->4, 你应该返回 2->1->4->3.说明:你的算法只能使用常数的额外空间。你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。解法一迭代版,设置一个指针 p 每次处理其后面的两个节点,若存在两个则...

2018-08-17 13:36:58 120

原创 每日一恋 - LeetCode 147 & 148. 对链表进行排序

147. 对链表进行插入排序插入排序的动画演示如上。从第一个元素开始,该链表可以被认为已经部分排序(用黑色表示)。每次迭代时,从输入数据中移除一个元素(用红色表示),并原地将其插入到已排好序的链表中。插入排序算法:插入排序是迭代的,每次只移动一个元素,直到所有元素可以形成一个有序的输出列表。每次迭代中,插入排序只从输入数据中移除一个待排序的元素,找到它在序列中适当的位置,...

2018-08-17 11:37:51 1250

原创 每日一恋 - LeetCode 328. Odd Even Linked List(奇偶链表)

题目描述给定一个单链表,把所有的奇数节点和偶数节点分别排在一起。请注意,这里的奇数节点和偶数节点指的是节点编号的奇偶性,而不是节点的值的奇偶性。请尝试使用原地算法完成。你的算法的空间复杂度应为 O(1),时间复杂度应为 O(nodes),nodes 为节点总数。示例 1:输入: 1->2->3->4->5->NULL输出: 1->3-&gt

2018-08-17 09:10:34 93

原创 每日一恋 - LeetCode 86. Partition List(分隔链表)

题目描述给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前。你应当保留两个分区中每个节点的初始相对位置。(原地)示例:输入: head = 1->4->3->2->5->2, x = 3输出: 1->2->2->4->3->5分析如果没有原地的要求,可以使...

2018-08-17 08:38:49 138

原创 每日一恋 - LeetCode 82 & 83. Remove Duplicates from Sorted List(删除排序链表中的重复元素)

83 删除排序链表中的重复元素 题目描述给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。示例 1:输入: 1->1->2输出: 1->2示例 2:输入: 1->1->2->3->3输出: 1->2->3分析这道题,如果这样想:每次只比较相邻的两个结点,如果不同则向前移动;如果相同,则将删除相邻的...

2018-08-16 18:31:35 95

原创 每日一恋 - LeetCode 2 & 445 & 66 & 67 & 415. 数字相加

2. 两数相加给定两个非空链表来表示两个非负整数。位数按照逆序方式存储,它们的每个节点只存储单个数字。将两数相加返回一个新的链表。你可以假设除了数字 0 之外,这两个数字都不会以零开头。示例:输入:(2 -> 4 -> 3) + (5 -> 6 -> 4)输出:7 -> 0 -> 8原因:342 + 465 =

2018-08-16 15:50:23 140

原创 每日一恋 - LeetCode 43. Multiply Strings(字符串相乘)

题目描述给定两个以字符串形式表示的非负整数 num1 和 num2,返回 num1 和 num2 的乘积,它们的乘积也表示为字符串形式。示例 1:输入: num1 = "2", num2 = "3"输出: "6"示例 2:输入: num1 = "123", num2 = "456"输出: "56088"说明:num1 和 num2 的长度小于110

2018-08-16 13:54:59 393

原创 每日一恋 - LeetCode 217 & 219 & 220 . Contains Duplicate(存在重复元素)

LeetCode 217 题目描述:给定一个整数数组,判断是否存在重复元素。如果任何值在数组中出现至少两次,函数返回 true。如果数组中每个元素都不相同,则返回 false。示例 1:输入: [1,2,3,1]输出: true示例 2:输入: [1,2,3,4]输出: false示例 3:输入: [1,1,1,3,3,4,3,2,4,2]输出: ...

2018-08-10 20:11:07 151

原创 每日一恋 - LeetCode 283. Move Zeroes(移动零)

题目描述:Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.Example:Input: [0,1,0,3,12]Output: [1,3,12,0,0]Note...

2018-08-10 15:26:26 109

原创 每日一恋 - LeetCode 203 & 19 & 237. Remove Linked List Elements(删除链表中的节点)

题目描述:Remove all elements from a linked list of integers that have value val.Example:Input: 1->2->6->3->4->5->

2018-08-10 15:00:48 92

原创 每日一恋 - LeetCode 80. Remove Duplicates from Sorted Array II(删除排序数组中的重复项 II)

题目描述:Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.Do not allocate extra space for another array, you must do this...

2018-08-10 14:36:33 87

原创 每日一恋 - LeetCode 27. Remove Element(删除排序数组中的重复项)

题目描述:Given an array nums and a value val, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the inp...

2018-08-10 14:21:32 132

原创 每日一恋 - LeetCode 26. Remove Duplicates from Sorted Array(删除排序数组中的重复项)

题目描述:Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by ...

2018-08-10 13:57:51 185

原创 每日一恋 - LeetCode 75. Sort Colors(颜色分类)

题目描述:Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use...

2018-08-10 13:34:04 203

原创 每日一恋 - LeetCode 76. Minimum Window Substring(最小覆盖子串)

题目描述: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 ...

2018-08-10 11:53:45 132

原创 每日一恋 - 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 ...

2018-08-10 01:45:29 133

原创 每日一恋 - 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&q

2018-08-09 16:09:54 145

原创 每日一恋 - LeetCode 438. Find All Anagrams in a String(找到字符串中所有字母异位词)

Given a string s and a non-empty string p, find all the start indices of p’s anagrams in s.Strings consists of lowercase English letters only and the length of both strings s and p will not be large...

2018-08-09 14:19:12 480

原创 每日一恋 - LeetCode 234. Palindrome Linked List(回文链表)

description: 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 ...

2018-08-05 19:51:49 124

原创 每日一恋 LeetCode 92 & 206. Reverse Linked List (反转链表)

Description: Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5-&gt

2018-08-05 19:47:51 136

空空如也

空空如也

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

TA关注的人

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