-
-
Notifications
You must be signed in to change notification settings - Fork 195
[grapefruitgreentealoe] WEEK 01 solutions #1130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[grapefruitgreentealoe] WEEK 01 solutions #1130
Conversation
var containsDuplicate = function (nums) { | ||
const numberSet = new Set(); | ||
//시간 복잡도 O(n) | ||
for (i of nums) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안녕하세요! 첫 리뷰 남겨봅니다!
i 변수가 let, const로 선언되어 있지 않아 JS에서 자동으로 전역 변수로 취급되어 글로벌 스코프 오염 문제가 발생할 수 있을 것 같습니다.
지금처럼 단순한 로직에서는 큰 문제가 없어 보이지만, 복잡한 코드에서는 신경 써야 할 것 같습니다~!
6b72441
to
9e20a2f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다양한 방법으로 올려주셔서 좋았습니다 굿굿!!
var twoSum = function (nums, target) { | ||
//순회. target에서 nums[i]를 뺀 요소를 찾기. | ||
//2중포문. 시간복잡도 O(1)~O(N^2) | ||
for (let i = 0; i < nums.length; i++) { | ||
const subNum = target - nums[i]; // 공간 O(1) | ||
for (let j = i + 1; j < nums.length; j++) { | ||
if (nums[j] == subNum) { | ||
return [i, j]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
역시 시작은 다 이렇게..ㅋㅋ (저만 그런게 아니였네요)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다!!
1주차 고생많으셨습니다! 이번주도 화이팅입니다~ |
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!