Skip to content

Commit

Permalink
Merge pull request #102 from da-in/dain
Browse files Browse the repository at this point in the history
[23-02-15] dain.js
  • Loading branch information
da-in authored Feb 15, 2023
2 parents 0200c60 + 0df17f0 commit c5979e5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 시간초과

function solution(maps) {
var n = maps.length;
var m = maps[0].length;
var q = [[0, 0, 1]];
var direction = [
[1, 0],
[-1, 0],
[0, 1],
[0, -1],
];

while (q.length > 0) {
let [i, j, c] = q.shift();
maps[i][j] = 0;
if (i == n - 1 && j == m - 1) {
return c;
}
for (d of direction) {
if (maps[i + d[0]] && maps[i + d[0]][j + d[1]]) {
q.push([i + d[0], j + d[1], c + 1]);
}
}
}
return -1;
}
17 changes: 17 additions & 0 deletions Programmers - 고득점 Kit/[그리디] 구명보트/dain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function solution(people, limit) {
var answer = 0;
people.sort((a, b) => a - b);
while (people.length > 0) {
answer += 1;
let a = people.pop();
if (limit - a >= people[0]) {
for (let i = 0; i < people.length; i++) {
if (people[i] <= limit - a) {
people.splice(i, 1);
break;
}
}
}
}
return answer;
}

0 comments on commit c5979e5

Please sign in to comment.