๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ/์ž๋ฃŒ๊ตฌ์กฐ & ์•Œ๊ณ ๋ฆฌ์ฆ˜

์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํ’€์ด ๋ชจ์Œ

by 1mj 2022. 7. 8.

๋‘ ์ •์ˆ˜ ์‚ฌ์ด์— ์†ํ•œ ์ •์ˆ˜์˜ ํ•ฉ ๊ตฌํ•˜๊ธฐ

 

function solution(a, b) {
	return (a + b) * (Math.abs(b - a) + 1) / 2;
}

 

 

๋‘ ๋ฒกํ„ฐ์˜ ๊ฐ ์„ฑ๋ถ„๋ผ๋ฆฌ์˜ ๊ณฑ์˜ ํ•ฉ์‚ฐ(๋‚ด์ ) ๊ตฌํ•˜๊ธฐ

 

function solution(a, b) {
	// a, b ๋ฐฐ์—ด์˜ ๊ธธ์ด๊ฐ€ ๋™์ผํ•จ์œผ๋กœ ๊ฐ€์ •
	return a.reduce((acc, _, i) => acc += a[i] * b[i], 0);
}

 

 

0๋ถ€ํ„ฐ 9๊นŒ์ง€์˜ ์ˆซ์ž ์ค‘ ์—†๋Š” ์ˆซ์ž ๋”ํ•˜๊ธฐ

 

function solution(numbers) {
    return 45 - numbers.reduce((cur, acc) => cur + acc, 0);
}

 

'๊ฐœ๋ฐœ > ์ž๋ฃŒ๊ตฌ์กฐ & ์•Œ๊ณ ๋ฆฌ์ฆ˜' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

LeetCode - Missing Number  (0) 2022.05.30
๋ชจ์˜๊ณ ์‚ฌ (Java)  (0) 2022.02.15
K๋ฒˆ์งธ์ˆ˜ (Java)  (0) 2022.02.09
์ฒด์œก๋ณต (Java)  (0) 2022.02.08
์ฃผ์‹ ๊ฐ€๊ฒฉ (Java)  (0) 2022.02.06

๋Œ“๊ธ€