-
-
Notifications
You must be signed in to change notification settings - Fork 195
[gitsunmin] WEEK 01 Solutions #323
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
Conversation
contains-duplicate/gitsunmin.ts
Outdated
*/ | ||
function containsDuplicate(nums: number[]): boolean { | ||
return new Set(nums).size !== nums.length | ||
}; |
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.
파일 마지막에 line break를 추가해주실 수 있으실까요? 코드 포멧터를 쓰시면 자동으로 추가될겁니다. (참고: https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline)
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.
수정했습니다 감사합니다~
function hammingWeight(n: number): number { | ||
return n.toString(2).replaceAll('0', '').length | ||
} |
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.
이렇게 간단하게 해결하는 방법도 있었네요! 👍👍
const expandAroundCenter = (s: string, left: number, right: number): number => { | ||
if (left < 0 || right >= s.length || s[left] !== s[right]) { | ||
return 0; | ||
} | ||
return 1 + expandAroundCenter(s, left - 1, right + 1); | ||
}; |
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.
안녕하세요! expandAroundCenter 함수를 countSubstrings 외부로 뺀 이유가 있으실까요?
countSubstrings 안에서 함수를 정의하면 파라매터로 s를 굳이 넘겨주지 않아도 될 것 같습니다.
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.
@nhistory
안녕하세요
아 넵 함수 내에서 다른 스코프의 변수를 참조하는게 안 좋다고 생각해서 파라미터로 받도록 했어요
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.
side effect를 고려하는 좋은 사고라고 생각합니다 어떤 분은 그런 pure function은 네이밍 컨벤션을 calc로 시작하도록 맞추기도 하시더라고요
const expandAroundCenter = (s: string, left: number, right: number): number => { | ||
if (left < 0 || right >= s.length || s[left] !== s[right]) { | ||
return 0; | ||
} | ||
return 1 + expandAroundCenter(s, left - 1, right + 1); | ||
}; |
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.
side effect를 고려하는 좋은 사고라고 생각합니다 어떤 분은 그런 pure function은 네이밍 컨벤션을 calc로 시작하도록 맞추기도 하시더라고요
다섯 문제 제출합니다 🙏