class Solution: def grayCode(self, n: int) -> List[int]: r = [0] for i in range(n): r.extend([x | 1<<i for x in r[::-1]]) return r 或者直接背格雷码的公式🥶吧:class Solution: def grayCode(self, n: int) -> List[int]: re
Check if a given number is a perfect square with only addition or substraction operation. eg. 25 returns true; 19 returns false. Perfect square number 有一个特性,比如0,1,4,9,16,25 他们之间的间隔分别是1,3,5,7,9,每次间隔都是i+2. 所以每次往下减i, i 更新成i+2. 看最后结果是否为0即...
packageleetcode// 解法一 O(n^2)funcisSubsequence(sstring,tstring)bool{index:=0fori:=0;i<len(s);i++{flag:=falsefor;index<len(t);index++{ifs[i]==t[index]{flag=truebreak}}ifflag==true{index++continue}else{returnfalse}}returntrue}// 解法二 O(n)funcisSubsequence1(sstring,tstring...
This repository contains my solutions to LeetCode problems. Created with ️ by LeetPush Made by Tut: GitHub - LinkedIn Hüsam: GitHub - LinkedIn Happy coding! 🚀 LeetCode Topics Array 0026-remove-duplicates-from-sorted-array 0027-remove-element 0036-valid-sudoku 0037-sudoku-solver 0045-jump...
文章的的后半部分挑选了部分leetcode中典型应用二分思想的题目。1. 二分查找的总结这里贴上一份十分细节的讲解二分查找写法的核心在于缩小查找的边界,也就是不断地缩小查找范围,使得目标值在范围内。当查找范围为空集或找到了目标值时,就可以结束循环。如果懂得这个道理,二分查找写起来就简单多了。
This repository contains my solutions to LeetCode problems. Created with ️ by LeetPush Made by Tut: GitHub - LinkedIn Hüsam: GitHub - LinkedIn Happy coding! 🚀 LeetCode Topics Array 0334-increasing-triplet-subsequence 0416-partition-equal-subset-sum 0605-can-place-flowers 0724-find-pivot...
链接:https://leetcode-cn.com/problems/perfect-squares 思路: 这题之前用BFS的方法解决过,之前也说过,在DP算法中还会遇到 DP算法,还是要总结找归类的,如果就自己去找,去发现的话还挺困难的 从官方偷的图,先要找到在这个数之前的平方数有哪些,基本上的规律就是 ...
LeetCode: A popular platform for practicing coding problems, especially for interview preparation. HackerRank: Offers a variety of challenges across different domains and difficulty levels. GeeksforGeeks Practice: A platform dedicated to practicing coding problems with varying difficulty. Challenges Project ...
链接:https://leetcode-cn.com/problems/perfect-squares 思路: 这道题的解题办法有很多,既然先给他归类到了BFS类,就先用BFS的思路来解题。(动态规划中还要再做一次) 遍历完第一层再遍历第二层再第三层。。。 那么第二层,第三层分别是什么东西,怎么来的呢?
This repository contains the solutions and explanations to the algorithm problems on LeetCode. Only medium or above are included. All are written in C++/Python and implemented by myself. The problems attempted multiple times are labelled with hyperlinks.