-
-
Notifications
You must be signed in to change notification settings - Fork 195
[seunghyun] 1주차 답안 제출 #15
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
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.
중간 피드백 드렸습니다. 남은 문제 풀이도 화이팅입니다! 💪
class Solution { | ||
public boolean containsDuplicate(int[] nums) { | ||
Set<Integer> set = new HashSet<>(); | ||
|
||
for (int num : nums) { | ||
if (set.contains(num)) return true; | ||
set.add(num); | ||
} | ||
|
||
return false; | ||
} | ||
} |
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.
@DaleSeo 알고리즘의 어떠한 성능에 대한 분석을 어떻게 진행 해야하는지 몰라서요 😓
혹시 가이드 문서나 링크를 알려주신다면 참고해서 작성해 보도록 하겠습니다!
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.
https://www.algodale.com/guides/big-o-complexities/
시간복잡도와 공간복잡도에 대해서 찾아보시면 좋을 것 같습니다..!
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.
처음에 스스로 하기 어려우시다면 chatGPT 한테 코드를 주면서 시간복잡도와 공간복잡도를 알려달라고 해보시는걸 추천드립니다 : )
물론 다 믿진 마지고 왜 그렇게 나오는지, 진짜 맞는 답변인지도 꼭 확인해보세요...!
(가끔 틀리게 알려줍니다)
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.
@dev-jonghoonpark 감사합니다!!
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.
@DaleSeo @dev-jonghoonpark
안녕하세요 :)
anangram도 시간되실때 리뷰 부탁드립니다 🙏
* @param t | ||
* @return | ||
*/ | ||
public static boolean containsDuplicate(String s, String t) { |
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.
(순수 질문) static 추가되어도 leetcode에서 통과 되나요? 문제에서 기본 제공되는 템플릿에 static이 없었던걸로 기억해서 질문드려봅니다 : )
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.
앗 저도 leetcode는 static 키워드 제거하고 제출하였습니다.
leetcode에서 auto complete 기능을 못써서 intellij 에서 풀어보고 옮기다 보니 😢
valid-anagram/Seunghyun-Lim.java
Outdated
} | ||
} | ||
|
||
return map.size() == 0; |
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.
Java Map 에는 isEmpty가 있어서 그걸로 수정하면 더 의미가 직접적으로 오지 않을까 싶네요
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.
명확한 의미의 메서드를 사용하는게 좋겠어요! 감사합니다!
isEmpty() 반영 하였습니다.
valid-anagram/Seunghyun-Lim.java
Outdated
Map<Character, Integer> map = new HashMap<>(); | ||
|
||
for (int i = 0; i < s.length(); i++) { | ||
if (map.get(s.charAt(i)) == null) { |
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.
containsKey 를 쓰시면 더 직관적이지 않을까 생각됩니다 : )
getOrDefault 함수로 더 깔끔하게 짤수도 있을것 같네요...!
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.
s.charAt(i) 가 중복되어서 보이는게 아쉬운것 같습니다.
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.
명확한 의미의 containsKey()로 반영하였습니다.
getOrDefault()는 바로 떠오르지 않아서 한번 찾아보고 적용해보겠습니다!
아래 코드로 변경해서 반영했습니다. 🙏
char word = s.charAt(i);
map.put(word, (map.getOrDefault(word, 0) + 1));
valid-anagram/Seunghyun-Lim.java
Outdated
if (v == 0) { | ||
map.remove(word); | ||
} else { | ||
map.put(word, (map.get(word) - 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.
map.get(word) - 1 을 v 로 바꿀 수 있어보이는데 맞으면 v로 바꾸면 어떨까 싶습니다 : )
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.
@dev-jonghoonpark
앗 놓친 부분이 있었네요 ㅜㅜ 퇴근 후 반영하겠습니다!
귀한 시간 리뷰 해주셔서 정말 감사합니다 :)
1주차 문제풀이 Status
Contains Duplicate [Done]
Valid Anagram [Done]
Two Sum [Review]
Valid Palindrome [Review]
Best Time to Buy and Sell Stock [Review]