Skip to content

Commit 5f4f96a

Browse files
authored
Update 1066-campus-bikes-ii.js
1 parent 0436dd2 commit 5f4f96a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

1066-campus-bikes-ii.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
/**
2+
* @param {number[][]} workers
3+
* @param {number[][]} bikes
4+
* @return {number}
5+
*/
6+
const assignBikes = function(workers, bikes) {
7+
const n = workers.length, m = bikes.length
8+
let res = Infinity
9+
dfs(0, 0, 0)
10+
return res
11+
function dfs(i, mask, cur) {
12+
if(i === n) {
13+
res = Math.min(res, cur)
14+
return
15+
}
16+
for(let j = 0; j < m; j++) {
17+
if(((mask >> j) ^ 1) % 2 == 1) {
18+
dfs(i + 1, mask | (1 << j), cur + calc(i, j))
19+
}
20+
}
21+
}
22+
23+
function calc(i, j) {
24+
const a = workers[i], b = bikes[j]
25+
return Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1])
26+
}
27+
28+
};
29+
30+
// another
31+
132
/**
233
* @param {number[][]} workers
334
* @param {number[][]} bikes

0 commit comments

Comments
 (0)