Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- 배포
- 문자열처리
- node배포
- 철학
- computerscience
- 문자열
- lightsailor
- multer-s3
- 코드
- node.js
- 컴퓨터과학
- CS
- 파이썬
- 알고리즘
- Hill Climbing
- typescript
- 컴퓨터공학
- AWS
- Local Search
- Search Algorithm
- Simulated Annealing
Archives
- Today
- Total
지식의모듈화
[Leetcode][Javascript] 36. Valid Sudoku 본문
1. 1개의 Set사용
/**
* @param {character[][]} board
* @return {boolean}
*/
var isValidSudoku = function(board) {
let set= new Set();
for (let i=0; i<board.length; i++){
for(let j=0; j<board.length; j++){
if(board[i][j]==='.') continue;
else{
let subsquare= (3*Math.floor(i/3) +Math.floor(j/3))
const row=`${i}th row has ${board[i][j]}`
const col=`${j}th column has ${board[i][j]}`
const sub=`${subsquare}th square has ${board[i][j]}`
if(set.has(row)||set.has(col)||set.has(sub)){
return false;
}
else{
set.add(row)
set.add(col)
set.add(sub)
}
}
}
}
return true
};'PS > LeetCode' 카테고리의 다른 글
| [LeetCode][JavaScript] 442. Find All Duplicates in an Array (0) | 2022.08.17 |
|---|---|
| [Leetcode][JavaScript] 55. Jump Game (0) | 2022.08.17 |
| [LeetCode][Javascript] LinkedList Problems (0) | 2022.08.05 |
| [LeetCode][JavaScript] DFS Problems (0) | 2022.08.04 |
| [LeetCode][Javascript] Binary Search Tree Problems (0) | 2022.08.04 |