[u-siop] WEEK 01 solutions#2391
[u-siop] WEEK 01 solutions#2391SamTheKorean merged 2 commits intoDaleStudy:mainDaleStudy/leetcode-study:mainfrom
Conversation
| @@ -0,0 +1,20 @@ | ||
| class Solution { |
There was a problem hiding this comment.
์ ! C++๋ก ํธ์๋๊ตฐ์ ๐ ์ค๋๋ง์ด๋ค์ ใ ใ
์ด Extension ์จ๋ณด์
จ๋์?
https://discord.com/channels/775115965964222492/1229860988170403901/1479017249691013132
๋ฌธ์ ๋ฅผ ๋น ๋ฅด๊ฒ ํธ๋๋ฐ ๋์ ๋๋๊ฑฐ ๊ฐ์์~~ ํ์ดํ ์ ๋๋ค.
There was a problem hiding this comment.
์๊ฐ๋ด์ด ์ฝ๋ฉํธ ๋ฌ์์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.
์ต์คํ ์ ์ฌ์ฉํด๋ณด๊ณ ํผ๋๋ฐฑ๋ ํด๋ณด๊ฒ ์ต๋๋ค ใ ใ
| class Solution { | ||
| public: | ||
| bool containsDuplicate(vector<int>& nums) { | ||
| // instinct : sort the array and check all the array whether duplicate or not |
There was a problem hiding this comment.
์ต์ด ์ ๊ทผ์ ๋ํด ์์ฑํด์ฃผ์ ๊ฒ ์ธ์๊น์ต๋๋ค.
๊ฒฐ๊ณผ์ ์ผ๋ก๋ sort์์ด O(n)์๊ฐ ๋ณต์ก๋๋ก ๊ฐ์ ๋์๋ค์. ๐
| // time complexity : NlogN(sort) + N(check all the array) | ||
| // space complexity : 1 | ||
|
|
||
| // how do we, in real world, judge there is a duplicated element, definitely need a reference( another data strucrue) to check |
There was a problem hiding this comment.
์ง๊ด์ ์ธ ํด๊ฒฐ์ฑ ์ ์์ ํ์ ์ธก๋ฉด๋ ์ธ์๊น์ต๋๋ค. ์ด๋ค ์๊ฐ์ผ๋ก ๋ก์ง์ ์์ฑํ์ จ๋์ง ํ์ธ ํ ์ ์์ด์ ํฅ๋ฏธ๋กญ๋ค์.
| for (const auto& i : nums) { | ||
| if (seen[i] >= 1) | ||
| return true; | ||
| seen[i] = true; |
There was a problem hiding this comment.
seen[i]์ true๋ฅผ ํ ๋นํ๋๋ฐ, ์ฒดํฌ๋ >= 1๋ก ์ฒ๋ฆฌํ ๋ถ๋ถ์ด ๋์ ๋๋๋ค. C++์์ ํต์ฉ๋๋ ์ปจ๋ฒค์ ์ผ๊น์?
There was a problem hiding this comment.
์๊ฐ๋ด์ด ํผ๋๋ฐฑ ์ฝ๋ฉํธ ์ฃผ์ ์ ์ ๋ง ๊ฐ์ฌํฉ๋๋ค.
์กฐ๊ธ ๋ ๋์ ์ฝ๋๋ก ์์ ํ๋ ๊ณผ์ ์์ ๋ง์ ํ์ธํ์ง ๋ชปํ๋ค์.
๋จ์ํ ์ฝํ ๋ฌธ์ ๋ผ๋, ํ๋ก์ ํธ ํ์ ํ๋ค๋ ์๊ฐ์ผ๋ก PR ์ง์ ํ ๋ฒ ๋ ๋ณด๊ฒ ์ต๋๋ค.
๊ฐ์ฌํฉ๋๋ค.
There was a problem hiding this comment.
๊น๊ฒ ๊ณ ๋ คํด์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค!
C++๋ก ์ผ์ ํด๋ณธ์ ์ด ์์ด์, ์ค๋ฌด์์ ์ข
์ข
๊ทธ๋ ๊ฒ ํ์๋์ง ๊ถ๊ธํด์ ์ฌ์ญค๋ณธ ๋ถ๋ถ์ด์์ต๋๋ค!
ํน์๋ ์ง์ ํ๋ ๊ฒ ์ฒ๋ผ ๋๊ปด์ง์
จ๋ค๋ฉด ์ ๋ํ ํํ์ ์กฐ๊ธ ๊ฐ๋ค๋ฌ๊ฒ ์ต๋๋ค. ใ
ใ
๋ต์ ์ ์ถ ๋ฌธ์
์์ฑ์ ์ฒดํฌ ๋ฆฌ์คํธ
In Review๋ก ์ค์ ํด์ฃผ์ธ์.๊ฒํ ์ ์ฒดํฌ ๋ฆฌ์คํธ
Important
๋ณธ์ธ ๋ต์ ์ ์ถ ๋ฟ๋ง ์๋๋ผ ๋ค๋ฅธ ๋ถ PR ํ๋ ์ด์์ ๋ฐ๋์ ๊ฒํ ๋ฅผ ํด์ฃผ์ ์ผ ํฉ๋๋ค!