Leetcode 刷题
逆风飞扬fei
这个作者很懒,什么都没留下…
展开
-
leetcode 双指针算法专题
什么叫做双指针算法? 双指针是一种方法,一种思想一种技巧,也谈不上什么特别的算法,在二分查找中经常使用这个技巧,具体就是用两个变量动态的存储两个或者多个的结点,来方便我们进行一些操作,通常使用在线性结构中,比如说数组或者是链表。 在我们遇到像数组,链表这类数据结构的算法题目的时候,应该要想得到双指针的来解决问题。特别是链表类的题目,经常需要用到两个或多个指针配合来记忆链表上的节点,完成某些操作。链表这种数据结构也是树形结构和图的原型,所以有时候在关于图和树形结构的算法题目中也会用到双指针。 1、快慢指针 1原创 2020-12-18 10:35:09 · 282 阅读 · 0 评论 -
Day3-1 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. 方法一:直接遍历,一个个的把0往后面调整(但是有一个问题就是时间复杂度太高,leetcode不予通过) 比如说: [0,1,0,3,12] 看左边的 元素是否为零,右边的元素是否不为0,如果是这样的情况,就进行交换 并且一次循环只交换一次,再原创 2020-12-11 16:13:49 · 96 阅读 · 0 评论 -
Day2-2 leetcode 53. Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Follow up: If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach原创 2020-12-10 11:34:36 · 100 阅读 · 0 评论 -
Day2-1 leetcode202Happy number
Write an algorithm to determine if a number n is “happy”. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number e原创 2020-12-10 10:26:49 · 119 阅读 · 0 评论 -
Day1-1 leetcode 136 :Single numble
合理采用位运算 Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. Follow up: Could you implement a solution with a linear runtime complexity and without using extra memory? 两种解法,第一个是嵌套循环遍历,但是时间复杂度较高,消耗了太多的原创 2020-12-09 12:53:54 · 93 阅读 · 0 评论