dolog
2024.02.29 탐욕(Greedy) 알고리즘 Part 3 본문
// 백준 11509번 풍선 맞추기
// 어떤 예제에서 아래 풀이가 틀렸을까?
let fs = require('fs');
let input = fs.readFileSync('/dev/stdin').toString().split('\n');
let balloons = Number(input[0]);
let hegiht = input[1].split(" ").map(Number);
let arrow = 1;
for(let i = 0 ; i < balloons - 1 ; i++) {
if(height[i] - 1 === height[i + 1]) {
continue;
} else {
arrow++;
}
}
console.log(arrow);
1. BigInt
* Number 원시 값이 안정적으로 나타낼 수 있는 2^53 - 1(= 9007199254740991) 보다 큰 정수를 표현할 수 있는 내장 객체
* 정수 리터럴 뒤에 n을 붙이거나 (= 10n) 생성자 함수 BigInt()를 호출하여 생성할 수 있다.
* Math 객체의 메서드와 함께 사용할 수 없다.
* 타입은 'bigint' 이다.
const bigIntTestA = 9007199254740991n;
// 9007199254740991n
const bigIntTestB = BigInt(9007199254740991);
// 9007199254740991n
const bigIntTestC = BigInt("9007199254740991");
// 9007199254740991n
typeof bigIntTestA;
// 'bigint'
typeof bigIntTestA === typeof bigIntTestB && typeof bigIntTestA === typeof bigIntTestC;
// true
const bigNumber1 = BigInt(1000000000);
const bigNumber2 = 1000000000n;
console.log(bigNumber1 === bigNumber2);
// true
참고
1. https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/BigInt
'알고리즘' 카테고리의 다른 글
2024.03.21 배열 알고리즘 - 기초 (0) | 2024.03.21 |
---|---|
2024.03.20 자료구조 - 자바스크립트 배열 (0) | 2024.03.20 |
2024.03.06 탐욕(Greedy) 알고리즘 Part 4 (0) | 2024.03.06 |
2024.02.27 탐욕(Greedy) 알고리즘 Part 2 (0) | 2024.02.28 |
2024.02.22 탐욕(Greedy) 알고리즘 Part 1 (0) | 2024.02.22 |