https://leetcode.cn/problems/find-the-distance-value-between-two-arrays/submissions/597896241/
秒了
```js
const findMin = (arr, target) => {
let left = 0,
right = arr.length - 1;
let ans = -1;
while (left <= right) {
const mid = Math.floor((right + left) / 2);
const char = arr;
if (char < target) {
left = mid + 1;
ans = mid;
} else {
right = mid - 1;
}
}
return ans;
};
const findMax = (arr, target) => {
let left = 0,
right = arr.length - 1;
let ans = -1;
while (left <= right) {
const mid = Math.floor((right + left) / 2);
const char = arr;
if (char <= target) {
left = mid + 1;
} else {
right = mid - 1;
ans = mid;
}
}
return ans;
};
var findTheDistanceValue = function (arr1, arr2, d) {
arr2=arr2.sort((a,b)=>a-b)
let ans=0;
for (let index = 0; index < arr1.length; index++) {
const num = arr1;
const min = findMin(arr2, num);
const max = findMax(arr2, num);
const sep = Math.min(num - (arr2??num-d-1), (arr2??num+d+1) - num,Math.abs( (arr2??num+d+1) - num));
if(sep>d){
ans++
}
}
return ans
};
```
https://leetcode.cn/problems/find-if-path-exists-in-graph/submissions/598303765/
过
```js
var validPath = function (n, edges, source, destination) {
const arr = new Array(n).fill(0).map(() => []);
const visit = new Array(n).fill(false);
for (const of edges) {
arr.push(b);
arr.push(a);
}
const dfs = (pos) => {
if(pos==destination){
return true
}
if (visit) {
return false;
}
visit = true;
let ans = false;
for (let index = 0; index < arr.length && ans == false; index++) {
const item = arr;
ans = dfs(item);
}
return ans;
};
const ans=dfs(source)
return ans
};
```
https://leetcode.cn/problems/all-paths-from-source-to-target/submissions/598307446/
过
```js
var allPathsSourceTarget = function (graph) {
const ans = [];
const dfs = (pos, arr) => {
arr.push(pos);
if (pos == graph.length - 1) {
ans.push([...arr]);
arr.pop();
return;
}
for (let index = 0; index < graph.length ; index++) {
const item = graph;
dfs(item,arr);
}
arr.pop();
return;
};
dfs(0, []);
return ans;
};
```
https://leetcode.cn/problems/keys-and-rooms/submissions/598309416/
过`
```js
var canVisitAllRooms = function (rooms) {
const n = rooms.length;
const visit = new Array(n).fill(false);
let all=0;
const dfs = (pos) => {
if (visit) {
return false;
}
visit = true;
all++
for (let index = 0; index < rooms.length; index++) {
const item = rooms;
dfs(item);
}
};
dfs(0);
return rooms.length==all;
};
```
https://leetcode.cn/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph/submissions/598323095/
过了
```js
var countPairs = function (n, edges) {
const arr = new Array(n).fill(0).map(() => []);
const visit = new Array(n).fill(false);
for (const of edges) {
arr.push(b);
arr.push(a);
}
const dfs = (pos, sum) => {
if (visit) {
return 0;
}
visit = true;
sum = 1;
for (let index = 0; index < arr.length; index++) {
const item = arr;
sum += dfs(item, sum);
}
return sum;
};
const list = [];
let ret = 0;
let sum = 0;
for (let index = 0; index < n; index++) {
const ans = dfs(index);
if (ans !== 0) {
list.push(ans);
if (list.length != 1) {
ret+=ans*sum
}
sum += ans;
}
}
return ret
};
```
https://leetcode.cn/problems/minimum-score-of-a-path-between-two-cities/submissions/598406384/
打测例硬凹过去了
```js
var minScore = function (n, roads) {
n = n + 1;
const arr = new Array(n).fill(0).map(() => []);
for (const of roads) {
arr.push();
arr.push();
}
const dfs = (pos, sum, visit) => {
if (visit !== -1) {
visit = Math.min(visit, sum);
return visit;
}
let ans = sum;
visit=sum
for (let index = 0; index < arr.length; index++) {
const = arr;
ans = Math.min(ans, dfs(target, Math.min(sum, value), visit));
}
visit = ans;
return ans;
};
return dfs(1, Number.MAX_SAFE_INTEGER, new Array(n).fill(-1));
};
```