Conversation
hyejj19
left a comment
There was a problem hiding this comment.
๋ฌธ์ ํ์ด ํ์๋๋ผ ๊ณ ์๋ง์ผ์ จ์ต๋๋ค! ๋ค์ ํ ์ฃผ๋ ํ์ดํ ์ ๋๋ค~!!๐
| # Approach: | ||
| # - Use a hash set to track elements we have already seen. | ||
| # - Iterate through the array and if the current number already exists in the set, return True. | ||
| # - Otherwise, add the current number to the set. |
There was a problem hiding this comment.
์ค ์ค๋ช ์ด ์์ฒญ ๊ฐ๊ฒฐํ๋ค์..! ๐๐
| for c in nums: | ||
| currentL = 1 | ||
| j = 1 | ||
|
|
||
| while c+j in s: | ||
| s.remove(c+j) | ||
| currentL += 1 | ||
| j += 1 | ||
|
|
||
| j = 1 | ||
| while c-j in s: | ||
| s.remove(c-j) | ||
| currentL += 1 | ||
| j += 1 | ||
|
|
||
| longest = max(longest, currentL) |
There was a problem hiding this comment.
์ค! ๊ธฐ์ค ์์ c๋ฅผ ๊ธฐ์ค์ผ๋ก ์์ชฝ์ ์ ๊ฑฐํด์ ์ค๋ณต ํ์์ ๋ฐฉ์งํ๋ ์๋๊ตฐ์!๐๐
๊ทผ๋ฐ ๊ธฐ์ค์ ์ธ c๋ set์์ ์ ๊ฑฐ๋์ง ์์์, ๋ค์ ๋ฐ๋ณต์์ ์ด์ ์์๋ก ๋ฐ๊ฒฌ๋์ด์ ๋ถํ์ํ ํ์์ด ๋ ์๋ ์์ ๊ฒ ๊ฐ์ต๋๋ค! for๋ฌธ์์ ์๊ธฐ ์์ ์ ์ ๊ฑฐํ๋ ๋ก์ง์ ๋จผ์ ์ถ๊ฐํ๊ณ ์์ํ๋๊ฑด ์ด๋จ๊น์?
์ ๋ ์ด ๋ฌธ์ ๋ฅผ c-1 ์ด ์์ ๋ ํด๋น ์์๋ฅผ ์ฐ์๋ ์ซ์์ ์์์ด๋ผ๊ณ ๋ณด๊ณ , ๊ฑฐ๊ธฐ์๋ถํฐ +1 ํ๋ฉด์ longest ๋ฅผ ์ธ๋ ๋ฐฉ์์ผ๋ก ํ์๋๋ฐ set์ ์ ๊ฑฐ ์ํ๊ณ ํ ์ ์์ด์ ์ข ๋ ๊น๋ํด์ง ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค!
There was a problem hiding this comment.
์ ์ํด์ฃผ์ ๋ฐฉ๋ฒ์ด ๋ ๋์๊ฒ ๊ฐ๋ค์ ๊ฐ์ฌํฉ๋๋ค!
๋ต์ ์ ์ถ ๋ฌธ์
์์ฑ์ ์ฒดํฌ ๋ฆฌ์คํธ
In Review๋ก ์ค์ ํด์ฃผ์ธ์.๊ฒํ ์ ์ฒดํฌ ๋ฆฌ์คํธ
Important
๋ณธ์ธ ๋ต์ ์ ์ถ ๋ฟ๋ง ์๋๋ผ ๋ค๋ฅธ ๋ถ PR ํ๋ ์ด์์ ๋ฐ๋์ ๊ฒํ ๋ฅผ ํด์ฃผ์ ์ผ ํฉ๋๋ค!