leetcode

๋ฌธ์ œ Given an array of integers nums sorted in non - decreasing order, find the starting and ending position of a given target value. If target is not found in the array, return [-1, -1]. You must write an algorithm with O(log n) runtime complexity. Example 1: Input: nums = [5,7,7,8,8,10], target = 8 Output: [3,4] Example 2: Input: nums = [5,7,7,8,8,10], target = 6 Output: [-1,-1] Example 3: Input..
ํ•œ๋™์•ˆ ์†์„ ๋†“๊ณ  ์žˆ๋˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ณต๋ถ€๋ฅผ ๋ณธ๊ฒฉ์ ์œผ๋กœ ํ•˜๊ธฐ ์œ„ํ•ด์„œ leetcode๋ฅผ ์‹œ์ž‘ํ–ˆ๋‹ค. ๋ณดํ†ต ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค๋ฅผ ๋งŽ์ด ์“ฐ๋Š”๋ฐ, ๋‚˜ ์—ญ์‹œ๋„ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ๋ ˆ๋ฒจ 2๋ฅผ ํ•˜๊ณ  ์žˆ์—ˆ๋Š”๋ฐ. ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ๋ฅผ ํ’€๊ณ  ๊ณต๋ถ€ํ•œ ๋‚ด์šฉ์„ ๊ธฐ๋กํ•˜๊ณ  ์‹ถ์–ด์„œ ๊ฐ„ํŽธํ•œ ๋ฐฉ๋ฒ•์ด ์—†์„๊นŒ? ํ•˜๊ณ  ์ฐพ๋‹ค๊ฐ€ leetcode์— ์ •์ฐฉ์„ ํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค. ์†์„ ๋†“๊ณ  ์žˆ๋˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๋‹ค์‹œ ๊ณต๋ถ€ ์‹œ์ž‘ํ•˜๋‹ˆ ๊ฐ ์žก๋Š”๋ฐ ์‹œ๊ฐ„์ด ๋„ˆ๋ฌด ์˜ค๋ž˜ ๊ฑธ๋ ธ๋‹ค. ์ด๋ฆฌ์ €๋ฆฌ ๋„์ „ํ•ด ๋ณด๋‹ค๊ฐ€ ์•ˆ๋˜๋ฉด ๊ทธ๋ƒฅ ๋ฐ”๋กœ ํžŒํŠธ๋ฅผ ๋ณด๊ฑฐ๋‚˜ ๋‹ต์„ ์ฐพ์•„๋ดค๋Š”๋ฐ ๋ฐฐ์—ด ํƒ์ƒ‰ํ•˜๋Š” ๋ฌธ์ œ๋ฅผ ๋งŒ๋‚  ๋•Œ๋งˆ๋‹ค ์ด๋Ÿฐ method? ์š”์†Œ? ๋ฅผ ๋ดค๋‹ค. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์–ธ์–ด๋กœ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ํ’€๋ฉด์„œ ํ•œ๋ฒˆ๋„ ๋งˆ์ฃผ ๋ชป ํ–ˆ๋˜ ๊ฒƒ์ด๋ผ์„œ ๋ฐ”๋กœ ๊ฒ€์ƒ‰ ๊ณ ๊ณ  - ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž๋ฃŒ๊ตฌ์กฐ์™€ ๊ด€๋ จ๋œ ๋‚ด์šฉ์ด์˜€๋‹ค. ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž๋ฃŒ๊ตฌ์กฐ์— ๋Œ€ํ•ด์„œ ์ฐพ์•„๋ณด๋ฉด ์ฃผ๋กœ C์–ธ์–ด๋‚˜ JAV..
์ƒ๋ฐ˜๊ธฐ ํšŒ๊ณ ๋ก์„ ๋ณด๋‹ค๊ฐ€ ํ•˜๋ฐ˜๊ธฐ์— ์ฝ”ํ…Œ๋ฅผ ํ•˜๋ฃจ์— ํ•œ๊ฐœ์”ฉ ํ•˜๊ฒ ๋‹ค๋Š” ์–ด๋ฆฌ์„์€(?!) ๊ณผ๊ฑฐ์˜ ๋‚˜ ์ž์‹ ์ด ๋‚ด๋ฑ‰์€(?!)์€ ๋ง์„ ๋ณด์•˜๋‹ค. ์†๊ฐ€๋ฝ์„ ๋ถ„์ง€๋ฅด๋˜๊ฐ€ํ•ด์•ผ์ง€... ...... ๊ทธ๋ ‡๋‹ค ๋ฐ˜์‘์„ ๋ณด๋ฉด ์•Œ๊ฒ ์ง€๋งŒ ์•ˆํ–ˆ๋‹ค. ์•„๋‹ˆ๋‹ค ๋ชป ํ–ˆ๋‹ค๋กœ ์ •์ •ํ•˜๊ฒ ๋‹ค. ๋‚˜์•ฝํ•œ ๋‚˜ ๋…€์„! ์ •์‹ ์ฐจ๋ ค๋ž!! ๋„ˆ๋ฌด ์ •์‹ ์ด ์—†์—ˆ๋‹ค.๋ผ๋Š” ๊ฑด ๋ณ€๋ช…์ด๊ธฐ๋„ํ•˜๊ณ ...์˜๋ฏธ์—†๋Š” ๋ณ€๋ช…์€ ์ง‘์–ด์น˜์šฐ์ž. ์•„๋ฌดํŠผ ๋’ค๋Šฆ๊ฒŒ ๋‚ด๊ฐ€ ์Ÿ์•„๋‚ธ ํ•˜๋ฐ˜๊ธฐ ๊ฒŒํš์„ ๋ณด๋‹ค๊ฐ€ ํ•œ๋‹ฌ ํ•˜๊ณ  ์กฐ๊ธˆ ๋” ๋‚จ์€ 2022๋…„. ๋งˆ์ง€๋ง‰๊นŒ์ง€ ์ตœ์„ ์„ ๋‹คํ•ด๋ณด์ž๋ผ๋Š” ๋งˆ์Œ์œผ๋กœ LeetCode ์— ์ ‘์†ํ–ˆ๋‹ค. ์ฝ”ํ…Œ๋ฅผ ์ข€๋” ํšจ์œจ์ ์ธ ๋ฐฉ๋ฒ•์œผ๋กœ ํ•  ์ˆ˜ ์—†์„๊นŒ? ๊ณ ๋ฏผํ•˜๋‹ค๊ฐ€ github์— ๋‚จ๊ธฐ์ž๋ผ๋Š” ์ƒ๊ฐ์„ ํ•˜๊ฒŒ ๋˜์—ˆ๊ณ , leecode๋Š” github๊ณผ ์ž๋™์—ฐ๋™์„ ํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•ด์„œ ! ใ…‡ใ…‹ใ„ทใ…‹ LeetCode์™€ github์„ ์—ฐ..
๋ฐ(Ming) ๐Ÿฐ
'leetcode' ํƒœ๊ทธ์˜ ๊ธ€ ๋ชฉ๋ก