李恒道 发表于 2025-1-29 03:04:23

https://leetcode.cn/problems/double-modular-exponentiation/submissions/595784284/
这题真的涨知识了
太卡边界了
```js
var getGoodIndices = function (variables, target) {
let ans = [];
for (let index = 0; index < variables.length; index++) {
    const = variables;
    if (pow(pow(a, b, 10), c, d) == target) {
      ans.push(index);
    }
}
return ans;
};

const pow = (a, b, mod) => {
let mul = a;
let ans = 1;
while (b !== 0) {
    if ((b & 1 )!== 0) {
      ans = ans*mul% mod;
    }
    b = b >> 1;
    mul = mul * mul% mod;
}
return ans;
};
```

李恒道 发表于 2025-1-29 03:05:02

https://leetcode.cn/submissions/detail/595784111/
全排列
```js
var permuteUnique = function (nums) {
const swap = (a, b) => {
    const temp = nums;
    nums = nums;
    nums = temp;
};
const ans = [];
const cache = new Map();
const dfs = (i) => {
    if (i == nums.length - 1) {
      const tag = nums.join(" ");
      if (cache.has(tag) ) {
      return;
      }
      cache.set(tag, true);
      ans.push([...nums]);
      return;
    }
    for (let index = i; index < nums.length; index++) {
      swap(i, index);
      dfs(i + 1);
      swap(i, index);
    }
};
dfs(0);
return ans;
};
```

李恒道 发表于 2025-1-29 13:03:17

https://leetcode.cn/problems/people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list/submissions/595809496/
模拟题
map硬爆了
```js
var peopleIndexes = function (favoriteCompanies) {
const strToMap = new Map();
const list = [];
for (let index = 0; index < favoriteCompanies.length; index++) {
    const favoriteCompanie = favoriteCompanies;
    const set = new Set();
    for (let index = 0; index < favoriteCompanie.length; index++) {
      const str = favoriteCompanie;
      strToMap.set(str, strToMap.get(str) ?? []);
      strToMap.get(str).push(set);
      set.add(str);
    }
    list.push(set);
}
const cache = new Map();
const isChild = (setA, setB) => {
    if (cache.has(setA)) {
      if (cache.get(setA).has(setB)) {
      return cache.get(setA).get(setB);
      }
    }
    if (setA == setB) {
      return false;
    }
    let ans = true;
    for (const str of setB.values()) {
      if (setA.has(str) == false) {
      ans = false;
      break;
      }
    }
    if (cache.has(setA) == false) {
      cache.set(setA, new Map());
    }
    if (cache.get(setA).has(setB) == false) {
      cache.get(setA).set(setB, ans);
    }
    return ans;
};
let ans = [];
for (let index = 0; index < list.length; index++) {
    const item = list;
    let noChild = true;
    for (const str of item.values()) {
      for (const setA of strToMap.get(str)) {
      if (isChild(setA, item)) {
          noChild = false;
      }
      if (!noChild) {
          break;
      }
      }
      if (!noChild) {
      break;
      }
    }
    if (noChild) {
      ans.push(index);
    }
}
return ans;
};
```

李恒道 发表于 2025-1-29 13:22:49

https://leetcode.cn/problems/average-salary-excluding-the-minimum-and-maximum-salary/submissions/595810894/?envType=study-plan-v2&envId=programming-skills
平均提,秒了
```go
func average(salary []int) float64 {
var maxValue,minValue float64= float64(salary), float64(salary)
var total float64
        for i := 0; i < len(salary); i++ {
                total+=float64(salary);
                maxValue= math.Max(maxValue, float64(salary))
                minValue= math.Min(minValue, float64(salary))
        }
        return (total - maxValue - minValue) / float64(len(salary) - 2)
}
```

李恒道 发表于 2025-1-29 13:28:41

https://leetcode.cn/problems/maximum-69-number/submissions/595811321/
秒了
```go
func maximum69Number (num int) int {
str:=[]rune(strconv.Itoa(num))
        for i := 0; i < len(str); i++ {
                if str=='6' {
                        str='9'
            break;
                }
        }
        ret,_:=strconv.Atoi(string(str))
        returnret
}
```

李恒道 发表于 2025-1-29 14:24:42

https://leetcode.cn/problems/rotating-the-box/submissions/595815430/
秒了
```js
var rotateTheBox = function (boxGrid) {
const rotatedMatrix = rotateMatrix(boxGrid);
for (let index = rotatedMatrix.length - 1; index >= 0; index--) {
    for (let indey = 0; indey < rotatedMatrix.length; indey++) {
      let x = index;
      const char = rotatedMatrix;
      if (char == "#") {
      rotatedMatrix = ".";
      while (x + 1 < rotatedMatrix.length&& rotatedMatrix == ".") {
          x = x + 1;
      }
      rotatedMatrix = char;
      }
    }
}
return rotatedMatrix
};
function rotateMatrix(matrix) {
const rows = matrix.length;
const cols = matrix.length;
const result = Array.from({ length: cols }, () => Array(rows).fill(0));

for (let i = 0; i < rows; i++) {
    for (let j = 0; j < cols; j++) {
      result = matrix;
    }
}

return result;
}
```

李恒道 发表于 2025-1-30 00:07:17

https://leetcode.cn/problems/intersection-of-two-arrays-ii/submissions/595881524/
穿了
```js
var intersect = function (nums1, nums2) {
const map1 = new Map();
for (const num of nums1) {
    map1.set(num, (map1.get(num) ?? 0) + 1);
}
let ans=[]
for (const num of nums2) {
    if (map1.has(num)) {
      let times = map1.get(num);
      ans.push(num)
      times--
      if(times==0){
      map1.delete(num)
      }else{
      map1.set(num,times)
      }
    }

}
return ans
};
```

李恒道 发表于 2025-1-30 00:08:12

https://leetcode.cn/problems/intersection-of-two-arrays/submissions/595881599/
穿
```js
var intersection= function (nums1, nums2) {
const map1 = new Map();
for (const num of nums1) {
    map1.set(num, (map1.get(num) ?? 0) + 1);
}
let ans=[]
for (const num of nums2) {
    if (map1.has(num)) {
      let times = map1.get(num);
      ans.push(num)
      times--
      map1.delete(num)
    }

}
return ans
};
```

李恒道 发表于 2025-1-30 14:35:53

https://leetcode.cn/problems/students-and-examinations/?envType=study-plan-v2&envId=sql-free-50
大过年做个sql水一下
```js
SELECT Students.*, Subjects.*, COUNT(Examinations.subject_name) AS attended_exams
FROM Students
CROSS JOIN Subjects
LEFT JOIN Examinations ON
    Students.student_id = Examinations.student_id AND Subjects.subject_name =Examinations.subject_name
GROUP BY
    Students.student_id,
    Subjects.subject_name
ORDER BY
    Students.student_id,
    Subjects.subject_name;
```

李恒道 发表于 2025-1-30 16:26:04

https://leetcode.cn/problems/confirmation-rate/submissions/595949163/?envType=study-plan-v2&envId=sql-free-50
sql也还挺有意思的
```js
# Write your MySQL query statement below
SELECT Signups.user_id ,Round((COUNT(CASE WHEN action= 'confirmed' THEN 1 END)/COUNT(*)),2) AS confirmation_ratefrom Signups LEFT JOIN Confirmations ON Signups.user_id=Confirmations.user_id
GROUP BY Signups.user_id
```
页: 37 38 39 40 41 42 43 44 45 46 [47] 48 49 50 51 52 53 54
查看完整版本: 【当前排名42710】挑战leetcode进入前1w名