๐Ÿฅž BE
home

561_Array Partition 1

๋‹ด๋‹น์ž
์™„๋ฃŒ ์—ฌ๋ถ€
Solved
์š”์•ฝ
๋‚ ์งœ
2024/07/04
ํƒœ๊ทธ
์ž๋ฃŒ๊ตฌ์กฐ
๊ตฌํ˜„
๋‚œ์ด๋„
Easy
์ถœ์ฒ˜
LeetCode

์ฝ”๋“œ

import java.util.Arrays; class Solution { // min(a, b) ํ˜•์‹์˜ ํ•ฉ์œผ๋กœ ์ตœ๋Œ€์˜ ์ˆ˜๋ฅผ ๊ตฌํ•˜๋ ค๋ฉด, ๊ทธ๋ƒฅ ํŽ˜์–ด์— ์ˆซ์ž๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ๋‘๊ฐœ์”ฉ ๋„ฃ์œผ๋ฉด ๋œ๋‹ค. public int arrayPairSum(int[] nums) { Arrays.sort(nums); int ans = 0; for (int i = 0; i < nums.length; i += 2) { ans += nums[i]; } return ans; } }
Java
๋ณต์‚ฌ

๋ฌธ์ œ ํ•ด๊ฒฐ ์•„์ด๋””์–ด

์ค‘์•™ํ™•์žฅ๋ฐฉ์‹์„ ํ™œ์šฉํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. ๋ฒ”์œ„ ๋‚ด์—์„œ ํŒฐ๋ฆฐ๋“œ๋กฌ์„ ๋งŒ๋‚ฌ์„ ๋•Œ, ํ•ด๋‹น ๋ถ€๋ถ„๋ถ€ํ„ฐ ํ™•์žฅ๋˜๋Š” ํฌ์ธํ„ฐ๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋กœ์ง์ด ํ•ต์‹ฌ์ด๋‹ค. ๋ฌธ๋ฒ• ์ž์ฒด๋Š” ์–ด๋ ต์ง€ ์•Š์ง€๋งŒ ๋ฌธ์ œ ์ดํ•ด ๋‚œ์ด๋„๊ฐ€ ๋†’์•˜๋‹ค.