LeetCode刷题笔记篇
文章平均质量分 66
Jack-He
一个人的成就,不是以金钱衡量,而是一生中,你善待过多少人,有多少人怀念你。 生意人的账簿,记录收入与支出,两数相减,便是盈利。 人生的账簿,记录爱与被爱,两数相加,就是成就。
展开
-
LeetCode刷题笔记(Two Sum)
为了明年的春招,小增也打算用LeetCode刷刷题。刚刚接触这款在线平台,对其不甚熟悉,具体的使用介绍请参照博客:https://blog.csdn.net/seabiscuityj/article/details/80730733言归正传,今天做的题比较简单,具体题目如下:Given an array of integers, returnindicesof the two numb...原创 2018-12-05 18:06:22 · 362 阅读 · 2 评论 -
LeetCode刷题笔记(Kth Largest Element in an Array)
今天刷的题目思路非常清晰。具体题目如下:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.Example 1:Input: [3,2,1,5,6,4]...原创 2019-01-10 20:51:21 · 309 阅读 · 0 评论 -
LeetCode刷题笔记(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 t...原创 2019-01-06 21:14:25 · 172 阅读 · 0 评论 -
LeetCode刷题笔记(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,1...原创 2019-01-02 21:20:42 · 225 阅读 · 0 评论 -
LeetCode刷题笔记(Remove Duplicates from Sorted Array)
今天刷的题目不算太难,但是中途一些测试用例还是挺厉害的,把程序的bug都一一找出来了。 具体题目如下: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 ex...原创 2019-01-07 18:55:18 · 149 阅读 · 0 评论 -
LeetCode刷题笔记(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 i...原创 2019-01-07 21:48:47 · 110 阅读 · 0 评论 -
LeetCode刷题笔记(Merge Sorted Array)
今天刷的题目思路不难,但想把代码做得更完美还是有一定难度的。 具体题目如下:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The number of elements initialized in nums1 and nums2 ar...原创 2019-01-08 21:54:49 · 246 阅读 · 0 评论 -
LeetCode刷题笔记(Valid Palindrome)
最近由于感冒了,几天都没有刷题了,刚刚刷了一道不算很难的题,但是与之前的数值型问题相比明显有些生疏,所以后期仍需加强这方面的练习。具体题目如下:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note: For th...原创 2019-01-20 14:45:41 · 156 阅读 · 0 评论 -
LeetCode刷题笔记(Reverse String)
今天趁着编程的热情还在,又找了一道不难的题刷了下,感觉还好。具体题目如下:Write a function that takes a string as input and returns the string reversed.Example 1:Input: "hello"Output: "olleh"Example 2:Input: "A man, a plan, ...原创 2019-01-20 19:05:11 · 192 阅读 · 0 评论 -
LeetCode刷题笔记(Reverse Vowels of a String)
紧接着笔者又刷了一道题,感觉套路和之前很类似。具体题目如下:Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Input: "hello"Output: "holle"Example 2:Input: "leetcode"Outp...原创 2019-01-20 20:09:36 · 190 阅读 · 0 评论 -
LeetCode刷题笔记(Container With Most Water)
刚刚找来一道题刷了一下,中间还是遇到了一些麻烦,下面就来好好总结一下。具体题目如下:Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoint...原创 2019-01-21 11:17:00 · 120 阅读 · 0 评论 -
LeetCode刷题笔记(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 ...原创 2019-01-15 18:53:50 · 128 阅读 · 0 评论 -
LeetCode刷题笔记(Minimum Size Subarray Sum)
今天刷了一道难度适中的题目,感觉还凑合,下面就来总结一下经验吧。具体题目如下:Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, r...原创 2019-01-22 15:16:22 · 224 阅读 · 0 评论 -
LeetCode刷题笔记(Intersection of Two Arrays)
今天精神较好,刷了一道中档题,感觉还不错,下面和大家分享一下经验吧!具体题目如下:Given two arrays, write a function to compute their intersection.Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2]Example 2:Input: nums...原创 2019-02-22 09:20:05 · 154 阅读 · 0 评论 -
LeetCode刷题笔记(Intersection of Two Arrays II)
忍不住又刷了一道题,这个题的答案或许会因不同语言的标准库而略有不同,下面来总结一下经验吧! 具体题目如下:Given two arrays, write a function to compute their intersection.Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2,2]Example 2...原创 2019-02-22 10:46:23 · 156 阅读 · 0 评论 -
LeetCode刷题笔记(Longest Substring Without Repeating Characters)
大家新年好,今天刷了新年后的第一道题,整体感觉还行,下面来分享下做题的经验吧!具体题目如下:Given a string, find the length of the longest substring without repeating characters.Example 1:Input: "abcabcbb"Output: 3 Explanation: The ans...原创 2019-02-18 09:24:45 · 202 阅读 · 0 评论 -
LeetCode刷题笔记(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 ...原创 2019-02-18 20:25:41 · 144 阅读 · 0 评论 -
LeetCode刷题笔记(4Sum)
这道题本来昨天就做完了,但由于昨天要主持支部组织生活会,所以才拖到了今天,下面来分享一下经验吧!Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique ...原创 2019-03-01 09:06:42 · 220 阅读 · 0 评论 -
LeetCode刷题笔记(3Sum Closest)
今天又刷了一道题,感觉对对撞指针这种方法又有了新的认识,下面就来总结一下吧!Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three intege...原创 2019-03-01 14:34:16 · 168 阅读 · 0 评论 -
LeetCode刷题笔记(Max Points on a Line)
雾霾持续严重,感觉很影响心情。但刷题依旧还得坚持下去哈,下面来总结一下刚刚刷完这道题的经验。题目如下:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.Example 1:Input: [[1,1],[2,2],[3,3]]Outp...原创 2019-03-05 09:59:13 · 162 阅读 · 0 评论 -
LeetCode刷题笔记(4Sum II)
以后打算每天早上刷题,刚刚又刷了一道题,本来很快就解决了的,但是由于下标问题,一直被坑着不能动,事实证明学习算法的人还是得细心呀,下面来分享下经验吧! 具体题目如下:Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B...原创 2019-02-26 09:03:42 · 149 阅读 · 0 评论 -
LeetCode刷题笔记(Contains Duplicate II)
今天天气不错,心情格外舒畅,刚刚刷了一道难度不大的题目,现在和大家分享一下经验。题目如下:Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the ...原创 2019-03-06 08:37:01 · 209 阅读 · 0 评论 -
LeetCode刷题笔记(Group Anagrams)
政协十三届二次会议于今天开幕,作为一名党员还是应该好好看看吧!言归正传,刚刚又刷了一道题,这道题还是有点难度的,所以参考了一下别人的解法,下面来分享一下经验吧!Given an array of strings, group anagrams together.Example:Input: ["eat", "tea", "tan", "ate", "nat", "bat"],原创 2019-03-03 10:15:27 · 203 阅读 · 0 评论 -
LeetCode刷题笔记(Contains Duplicate)
紧接着笔者又刷了一道和刚刚比较类似的题,并且这道题还简单些,下面来分享一下经验吧!题目如下:Given an array of integers, find if the array contains any duplicates.Your function should return true if any value appears at least twice in the a...原创 2019-03-06 09:43:15 · 197 阅读 · 0 评论 -
LeetCode刷题笔记(3Sum)
今天早上刷了一道题,感觉还是有点不容易,下面就来分享一下经验吧!Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.No...原创 2019-02-27 09:11:08 · 217 阅读 · 0 评论 -
LeetCode刷题笔记(Number of Boomerangs)
北京这几天wumai有点严重,lianghui期间出现这种事,某某部门人事变动可能会有点大吧。言归正传,刚刚又刷了一道题,感觉收获不小,下面和大家来分享一下吧!题目如下:Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such ...原创 2019-10-17 20:13:38 · 241 阅读 · 0 评论 -
LeetCode刷题笔记(Contains Duplicate III)
今天刷了一道题,感觉还是有点难度的,下面就来总结一下经验吧!题目如下:Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] i...原创 2019-03-07 09:06:32 · 168 阅读 · 0 评论 -
LeetCode刷题笔记(Reverse Linked List II)
今天又刷了一道链表的题,初次接触链表的题目,感觉还是有一定难度的,下面和大家来分享一下经验吧!题目如下:Reverse a linked list from position m to n. Do it in one-pass.Note: 1 ≤ m ≤ n ≤ length of list.Example:Input: 1->2->3->4->5-&...原创 2019-03-10 10:23:22 · 137 阅读 · 0 评论 -
LeetCode刷题笔记(Intersection of Two Linked Lists)
继续刷链表的题,感觉还是有一定的棘手,下面和大家来分享一下经验吧!题目如下:题意分析:给定两个单链表,找到它们的公共交点,并返回第一个交点的值。注:①如果两个链表没有交点,则返回NULL。 ②操作过程中应该保留两链表的原始结构 ③两链表均不为环状链表 ④算法要求的时间复杂度为O(n),空间复杂度为O(1)。解答如下...原创 2019-03-11 10:56:18 · 152 阅读 · 0 评论 -
LeetCode刷题笔记(Reverse Linked List)
今天是38妇女节,祝愿自己的母亲以及世界上所有的中老年女性节日快乐!刚刚尝试了一下链表的问题,难度不大,现在来分享一下经验吧!题目如下:Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLF...原创 2019-03-08 08:44:04 · 184 阅读 · 0 评论 -
LeetCode刷题笔记(Remove Duplicates from Sorted List)
今天刷了一道比较简单的链表题,感觉还是不顺手,下面和大家来分享一下经验吧!题目如下:Given a sorted linked list, delete all duplicates such that each element appear only once.Example 1:Input: 1->1->2Output: 1->2Example 2:...原创 2019-03-16 10:15:56 · 168 阅读 · 0 评论 -
LeetCode刷题笔记(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...原创 2019-03-17 15:39:57 · 293 阅读 · 0 评论 -
LeetCode刷题笔记(Valid Parentheses)
最近转移战线,开始准备进攻队列、栈和优先队列等相关的题目了。今天刷了一道与栈相关的题目,下面来分享一下经验吧!题目如下:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string...原创 2019-03-21 15:09:47 · 173 阅读 · 0 评论 -
LeetCode刷题笔记(Add Two Numbers II)
又刷了一道题,虽然是中档题,但是思路还是挺清楚的,下面就来和大家分享一下经验吧!题目如下:You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contai...原创 2019-03-18 10:04:21 · 164 阅读 · 0 评论 -
LeetCode刷题笔记(Partition List)
最近一直在刷链表的题目,感觉越来越顺手了,没有以前那么玄学了,下面和大家来分享一下经验吧!题目如下:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserv...原创 2019-03-19 09:26:24 · 182 阅读 · 0 评论 -
LeetCode刷题笔记(Odd Even Linked List)
趁热打铁,又刷了一道中档题,感觉难度还行,下面就和大家来分享一下经验吧!题目如下:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the val...原创 2019-03-19 10:47:23 · 199 阅读 · 0 评论 -
LeetCode刷题笔记(Evaluate Reverse Polish Notation)
刚刚又刷了一道题,感觉难度不是很大,下面就和大家分享一下经验吧!题目如下:Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expressi...原创 2019-03-23 10:07:50 · 188 阅读 · 1 评论 -
LeetCode刷题笔记(Binary Tree Preorder Traversal)
今天赶早刷了一道题,感觉这道题还是挺重要的,下面就和大家分享一下经验吧!题目如下:Given a binary tree, return the preorder traversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,2,3]Foll...原创 2019-03-30 09:47:45 · 219 阅读 · 0 评论 -
LeetCode刷题笔记(Binary Tree Inorder Traversal)
接下来又刷了一道类似的题目,思想和前面那道前序遍历差不多,下面就来分享一下经验。题目如下:Given a binary tree, return the inorder traversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,3,2]F...原创 2019-03-30 13:41:49 · 224 阅读 · 0 评论 -
LeetCode刷题笔记(Binary Tree Postorder Traversal)
趁热打铁顺便把后续遍历也刷了,其实前序、中序和后续遍历在代码表现上差别不是很大,下面来分享一下经验。题目如下:Given a binary tree, return the postorder traversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Outpu...原创 2019-03-30 14:02:50 · 153 阅读 · 0 评论