李恒道
发表于 2024-9-16 04:00:53
王一之 发表于 2024-9-16 03:19
nb 都13页了
115题了
还是没进10w
好像现在需要差不多250-300才能有排名
太恐怖了
李恒道
发表于 2024-9-16 21:17:32
https://leetcode.cn/problems/next-permutation/submissions/565262238/?envType=study-plan-v2&envId=top-100-liked
纯记忆的规则题
感觉都没什么学的必要...
```js
const swap = (arr, x, y) => {
arr ^= arr
arr ^= arr
arr ^= arr
}
var nextPermutation = function (nums) {
let hasNum = undefined
for (let index = nums.length - 2; index >= 0; index--) {
const num = nums;
const nextNum = nums;
if (num < nextNum) {
hasNum = index;
break;
}
}
if (hasNum!==undefined) {
for (let index = nums.length - 1; index > hasNum; index--) {
const num = nums;
if (num > nums) {
swap(nums, hasNum, index)
break;
}
}
const times = Math.floor((nums.length - hasNum - 1) / 2);
for (let index = hasNum + 1; index <= times + hasNum; index++) {
swap(nums, index, nums.length - (index - hasNum))
}
} else {
nums.reverse()
}
};
```
李恒道
发表于 2024-9-17 20:37:39
https://leetcode.cn/problems/n-th-tribonacci-number/?envType=study-plan-v2&envId=dynamic-programming
斐波那契数列
按道理应该也有齐次方程吧
懒得推了
```js
var tribonacci = function (n) {
const arr = ;
if(n<=2){
return arr
}
for (let index = 3; index <= n; index++) {
let num = arr + arr + arr;
arr.shift()
arr.push(num)
}
return arr.pop();
};
```
李恒道
发表于 2024-9-17 20:58:26
https://leetcode.cn/problems/min-cost-climbing-stairs/submissions/565511955/?envType=study-plan-v2&envId=dynamic-programming
一波秒!
```js
var minCostClimbingStairs = function (cost) {
const dp = new Array(cost.length);
dp = cost;
dp = cost;
for (let index = cost.length - 3; index >= 0; index--) {
dp = cost + Math.min(dp, dp);
}
return Math.min(dp, dp);
};
```
李恒道
发表于 2024-9-18 01:40:58
https://leetcode.cn/problems/delete-and-earn/submissions/565569533/?envType=study-plan-v2&envId=dynamic-programming
秒了
```js
var deleteAndEarn = function (nums) {
const newNum = []
const countCache = new Map()
for (let index = 0; index < nums.length; index++) {
const num = nums;
if (countCache.has(num)) {
countCache.set(num, countCache.get(num) + 1)
} else {
newNum.push(num)
countCache.set(num, 1)
}
}
newNum.sort((a, b) => a - b)
newNum.push(0)
newNum.push(0)
const dp = new Array(newNum.length + 2).fill(0)
for (let index = newNum.length - 3; index >= 0; index--) {
const num = newNum;
dp = newNum * countCache.get(newNum)
if (newNum == num + 1) {
dp += dp
dp = Math.max(dp, dp)
} else {
dp += dp
}
}
return Math.max(dp,dp)
};
```
李恒道
发表于 2024-9-18 03:28:04
https://leetcode.cn/problems/unique-paths-ii/submissions/565578976/?envType=study-plan-v2&envId=dynamic-programming
基础dp,秒了
```js
var uniquePathsWithObstacles = function (obstacleGrid) {
if(obstacleGrid.length - 1]==1){
return 0
}
const dp = new Array(obstacleGrid.length + 1).fill(0).map(() => new Array(obstacleGrid.length + 1).fill(0))
dp.length - 1]=1
for (let index = obstacleGrid.length - 1; index >= 0; index--) {
for (let indey = obstacleGrid.length - 1; indey >= 0; indey--) {
if( index==obstacleGrid.length-1&&indey==obstacleGrid.length - 1){
continue;
}
if (obstacleGrid == 1) {
dp = 0
continue;
}
const down = dp
const right = dp
dp = down + right
}
}
return dp
};
```
wuxin0011
发表于 2024-9-18 07:49:50
厉害,ggnb
李恒道
发表于 2024-9-18 08:53:26
wuxin0011 发表于 2024-9-18 07:49
厉害,ggnb
哥哥要不也开个贴一起玩
当打发时间了
多个人我也有危机感
{:4_115:}
wuxin0011
发表于 2024-9-18 23:59:57
李恒道 发表于 2024-9-18 08:53
哥哥要不也开个贴一起玩
当打发时间了
多个人我也有危机感
这是我LC主页: https://leetcode.cn/u/agitated-curranfnd/
wuxin0011
发表于 2024-9-19 00:02:36
刷题也就图一乐{:4_86:}