Provide all my solutions and explanations in Chinese for all the Leetcode coding problems. - grandyang/leetcode
1. 两数之和 - 力扣(LeetCode)class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: for i in range(len(nums)): for j in range(i + 1, len(nums)): if i != j and nums[i] + nums[j] == target: return [i, j] return []3. LeetCode 刷题攻略 3...
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. Topics algorithms leetcode cpp Resources Re...
classSolution(object):defuniquePaths(self,m,n):""":typem:int:typen:int:rtype:int"""dp=[[1]*n]+[[1]+[0]*(n-1)foriinrange(m-1)]print(dp)foriinrange(1,m):forjinrange(1,n):dp[i][j]=dp[i-1][j]+dp[i][j-1]returndp[m-1][n-1] 63. 不同路径 II(中等) 一个机...
1. 题目描述 题目链接:2731. 移动机器人 - 力扣(LeetCode)2. 解题思路 题目的大致意思是:在一条...
⚡️ Disclaimer: LeetCode reserves the right, in our sole discretion, to disqualify any entries where we believe a user undermines the fairness of this LeetCoding Challenge event, which includes, but is not limited to, copying and pasting solutions from other places directly into your submiss...
// Solution 1: Apparently N - 1 is a good base, so the problem is always solvable. As N - 1 is the upper bound for solutions, what we do next is to enumerate someparametersand solve some equations with binary search. It's numerical, so make sure you know things like error, truncat...
After, we can build a divide and conquer. Suppose we are looking at the interval S[i]...S[j] and it is supposed to represent L, R. Let's see whereM = (L+R)//2is supposed to start assuming the representation of [L, M-1] is untouched. We need to know how many digits are...
*/publicclassSolution3{privateint[]memory;publicintintegerBreak(intn){memory=newint[n+1];memory[0]=0;memory[1]=1;for(inti=2;i<=n;i++){intmaxValue=-1;for(intj=1;j<=i-1;j++){maxValue=max3(maxValue,j*(i-j),j*memory[i-j]);}memory[i]=maxValue;}returnmemory[n];}private...
[i + rowSize - 1][k] = num++;53}5455for(intk = i + rowSize - 2; k > i; k--) {//both the start and end need to be i, j, and also care about length56matrix[k][j] = num++;57}5859this.generateMatrixHelper(i + 1, j + 1, rowSize - 2, colSize - 2, matrix, ...