加载中
LeetCode | 每日一题 2021.04.28 | 633. 平方数之和

""" 逻辑:要使a^2+b^2=c, 那么a,b的取值范围一定在[0,sqrt(c)] 思路:这个题和计算雨水的题类似,用双指针将界限不断缩小 1.定义left,right两个指针;left=0|right=sqrt(c) 2.1 如果left^2+ri...

04/28 16:25
33
LeetCode | 每日一题 2021.04.27 | 938. 二叉搜索树的范围和

#938. 二叉搜索树的范围和 """ 题目求解的是在二叉树中满足x=[low,high]的所有值的和 思路: tip:因为存储数据是有序二叉树,所有root左边的值比root小,右边的值比root大 中序遍历,题目中是...

04/27 20:16
0
LeetCode.50 | Pow(x, n)

""" 方法a.暴力求解,本质求x的n次方就是n个x连乘 tips:需要n<0的情况; n的-2次=1/x的2次方 1.如果x=0,返回0 | 初始化返回结果值retPOW=1 2.判断n是否<0:如果n<0;将x转换成1/2,将n转成正值 ...

04/26 16:39
0
LeetCode.48 | 旋转图像

""" https://leetcode-cn.com/problems/rotate-image/solution/xuan-zhuan-tu-xiang-by-leetcode-solution-vu3m/ https://leetcode-cn.com/problems/rotate-image/solution/shu-ju-jie-gou-h...

04/15 15:57
40
LeetCode.47 | 全排列 II

""" https://leetcode-cn.com/problems/permutations-ii/solution/hot-100-47quan-pai-lie-ii-python3-hui-su-kao-lu-zh/ 思路: 和46的方法基本一致,回溯三要素: 1.有效结果 if len(slot)=....

04/11 09:19
70
LeetCode.46 | 全排列

""" https://leetcode-cn.com/problems/permutations/solution/di-gui-hui-su-xuan-shu-fa-yu-jiao-huan-fa-by-user5/ https://leetcode-cn.com/problems/permutations/solution/hot-100-46q...

2020/10/06 20:00
93
LeetCode.45 | 跳跃游戏 II

""" https://leetcode-cn.com/problems/jump-game-ii/solution/tiao-yue-you-xi-ii-by-leetcode-solution/ 思路:这是一个典型的贪婪算法:从局部优先->全局优先 1.遍历数组从0~n-1(不需要访问...

2020/09/10 16:02
1
LeetCode 44 | 通配符匹配

好久没写了,连最简单的DP都不太会了;看了好久的题解,最后把例子画出来才算正式完成. ''' https://leetcode-cn.com/problems/wildcard-matching/solution/tong-pei-fu-pi-pei-by-leetcode-so...

2020/09/04 16:30
0
LeetCode 34 | 在排序数组中查找元素的第一个和最后一个位置

""" https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/solution/er-fen-cha-zhao-suan-fa-xi-jie-xiang-jie-by-labula/ 思路:将nums分成左右两个...

2020/05/19 15:47
25
LeetCode.33 | 搜索旋转排序数组

""" https://leetcode-cn.com/problems/search-in-rotated-sorted-array/solution/pythonjs-er-fen-fa-33-sou-suo-xuan-zhuan-pai-xu-sh/ 思路:二分法,先判断有序域;再判断目标值在哪个列表域...

2020/05/18 16:36
36
LeetCode.32 | 最长有效括号

""" https://leetcode-cn.com/problems/longest-valid-parentheses/solution/zhan-he-dong-tai-gui-hua-liang-chong-jie-fa-by-ree/ https://leetcode-cn.com/problems/longest-valid-parent...

2020/05/14 20:18
33
LeetCode.31 | 下一个排列

""" https://leetcode-cn.com/problems/next-permutation/solution/xia-yi-ge-pai-lie-by-leetcode/ https://leetcode-cn.com/problems/next-permutation/solution/ti-yi-zhuan-hua-zhao-zui...

2020/04/21 15:37
60
LeetCode.30 | 串联所有单词的子串

""" https://leetcode-cn.com/problems/substring-with-concatenation-of-all-words/solution/30-chuan-lian-suo-you-dan-ci-de-zi-chuan-by-bu-jue/ 思路:此题较难,关键是给定字符串是不考虑...

2020/04/17 14:01
89
LeetCode.29 | 两数相除

""" https://leetcode-cn.com/problems/divide-two-integers/solution/chu-fa-dao-jian-fa-de-zhuan-hua-by-h_n/ 思路:此题比较困难,涉及了位移'<<'操作,位移实际就是2**n次方操作 先写出带有...

2020/04/16 14:41
63
LeetCode.28 | 实现 strStr()

""" 思路:利用滑动窗口,从左向右按needle的长度进行滑动;是否当前字符串current=needle 1.定义指针i,当前字符串current 2.1如果current=needle;返回当前i 2.2如果循结束,未找到匹配值,返回-...

2020/04/15 14:21
86
LeetCode.27|移除元素

""" https://leetcode-cn.com/problems/remove-element/solution/hua-jie-suan-fa-27-yi-chu-yuan-su-by-guanpengchn/ 思路:将数据分成left,right;left区域为未检查区,right为等值区 1.定义l...

2020/04/15 13:52
71
LeetCode.26|删除排序数组中的重复项

""" 思路:此题比较简单,用双指针就可以.原理和插入排序相似 1.定义左右指针,left,right 2.循环指针right 2.1如果left<>right,将right移到i+1位置 2.2如果left=right,继续循环 3.最后返......

2020/04/14 16:38
64
LeetCode.25 | K 个一组翻转链表

""" https://leetcode-cn.com/problems/reverse-nodes-in-k-group/solution/kge-yi-zu-fan-zhuan-lian-biao-by-powcai/ 思路:我理解此题是24的升级版;24是两两交换;此题是将值压入栈,并弹出完...

2020/04/09 20:04
87
LeetCode.24|两两交换链表中的节点

""" https://leetcode-cn.com/problems/swap-nodes-in-pairs/solution/liang-liang-jiao-huan-lian-biao-zhong-de-jie-di-19/ 思路:分为递归和迭代两种 方法I:递归 1.出口:当输入参数head=No...

2020/03/31 15:43
61
LeetCode.23 | 合并K个排序链表

""" https://leetcode-cn.com/problems/merge-k-sorted-lists/solution/he-bing-kge-pai-xu-lian-biao-by-leetcode/ 思路:还是以暴力遍历为主,先将链表->列表->列表.排序->新链表 1.新建一个...

2020/03/29 19:41
19

没有更多内容

加载失败,请刷新页面

返回顶部
顶部