Find Missing Range
Given a sorted integer array nums, where the range of elements are in the inclusive range [lower, upper], return its missing ranges.
๋ฌธ์ ๋ฅผ ์ ํํ๊ฒ ์ดํดํ๋ ๊ฒ์ด ์ค์ํ๋ค!
๋ฌธ์ ์์ ๋ฌป๋ ๊ฒ์ ์๋ ๋ฒ์์ ์ซ์๋ค์ ์ฐพ๋ ๊ฒ์ด ์๋๋ผ ๊ทธ ๋ฒ์๋ฅผ ์ฐพ๋ ๊ฒ์ด๋ค!
์ฃผ์ด์ง ์์๋ฅผ ํตํด ๊ฒฝ์ฐ์ ์๋ฅผ ์ปค๋ฒํ๋ค๊ณ ์๊ฐํ๊ณ ํ๊ธฐ!
Example 1 : Input : nums = [0,1,3,50,75], lower = 0 and upper = 99 Output : ["2", "4->49", "51->74", "76->99"]
Example 2 : Input : nums = [2,3,5,50,75], lower = 0 and upper = 99 Output : [0->1, 4, 6->49, 51->74, 76->99]
์๊ณ ๋ฆฌ์ฆ 1. ๊ฒฝ์ฐ์ ์์ ๋ฐ๋ผ ์ฝ๋๋ฅผ ์ธ๋ถํํ๋ค. 2-1. lower < nums[i] : (lower+1, nums[i]-1) 2. nums[i] + 1 < nums[i+1} : (nums[i]+1,nums[i+1}-1) 3. nums[nums.length-1] < upper : (nums[nums.length-1]+1,upper)
์๊ณ ๋ฆฌ์ฆ์ java๋ก ๊ตฌํ
Last updated