Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions leetcode3/황은지/385. Mini Parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* // This is the interface that allows for creating nested lists.
* // You should not implement it, or speculate about its implementation
* function NestedInteger() {
*
* Return true if this NestedInteger holds a single integer, rather than a nested list.
* @return {boolean}
* this.isInteger = function() {
* ...
* };
*
* Return the single integer that this NestedInteger holds, if it holds a single integer
* Return null if this NestedInteger holds a nested list
* @return {integer}
* this.getInteger = function() {
* ...
* };
*
* Set this NestedInteger to hold a single integer equal to value.
* @return {void}
* this.setInteger = function(value) {
* ...
* };
*
* Set this NestedInteger to hold a nested list and adds a nested integer elem to it.
* @return {void}
* this.add = function(elem) {
* ...
* };
*
* Return the nested list that this NestedInteger holds, if it holds a nested list
* Return null if this NestedInteger holds a single integer
* @return {NestedInteger[]}
* this.getList = function() {
* ...
* };
* };
*/
/**
* @param {string} s
* @return {NestedInteger}
*/
var deserialize = function (s) {
const nested = NestedInteger(s);
return nested.getInteger();
};
49 changes: 49 additions & 0 deletions leetcode3/황은지/463. Island Perimeter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @param {number[][]} grid
* @return {number}
*/
var islandPerimeter = function(grid) {

const ROW=grid.length;
const COL=grid[0].length;

//BFS
function doBFS(startR,startC){
const DIR=[[-1,0],[0,1],[1,0],[0,-1]]
const visited=Array.from({length:ROW},()=>Array(COL));
let count=0;

visited[startR][startC]=true;

const queue=[[startR,startC]];
let head=0;

while(head<queue.length){
const [curR,curC]=queue[head++];

for(let i=0;i<4;i++){
const [nextR,nextC]=[curR+DIR[i][0],curC+DIR[i][1]];
if(nextR<0 || nextR>=ROW || nextC<0 || nextC>=COL
|| grid[nextR][nextC]===0){
count++;
continue;
}
if(visited[nextR][nextC]) continue;
visited[nextR][nextC]=true;
queue.push([nextR,nextC]);
}
}
return count;

}


// 실행부
for(let i=0;i<ROW;i++){
for(let j=0;j<COL;j++){
if(grid[i][j]===1) return doBFS(i,j);
}
}


};