Skip to content

[leebeanbin] WEEK 01 Solution #1674

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions contains-duplicate/leebeanbin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.util.HashSet;

class Solution {
public boolean containsDuplicate(int[] nums) {
HashSet<Integer> arr = new HashSet<Integer>();
boolean answer = false;

for(int num : nums){
arr.add(num);
}

if(nums.length != arr.size()){
answer = true;
}

return answer;
Comment on lines +12 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

answer 사용의 목적이 nums.length != arr.size() 확인 용도라면 비교문 자체를 return해도 괜찮지 않을까요? return nums.length == arr.size(); 같이요!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생각해보니 그렇네요...!!

}
}
28 changes: 28 additions & 0 deletions two-sum/leebeanbin.java
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brute force와 map 사용 모두 잘 해주셨네요!
시간, 공간 복잡도도 계산해 주시면 좋을것 같습니다 :)

Copy link
Author

@leebeanbin leebeanbin Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위 부분은 어떤식으로 하면 될까요??? BigO 표기법 사용이 맞나요??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵넵 BigO 표기법 사용해 주시면 됩니다!

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.util.HashMap;

public class leebeanbin {
public static int[] bruteForce(int[] nums, int target) {
for (int i = 0; i < nums.length; i++) {
for (int j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] == target) {
return new int[]{i, j};
}
}
}
return null;
}

public static int[] hashMap(int[] nums, int target) {
HashMap<Integer, Integer> arr = new HashMap<>();

for (int i = 0; i < nums.length; i++) {
arr.put(nums[i], i);

if (arr.containsKey(target - nums[i])) {
return new int[]{arr.get(target - nums[i]), i};
}
}

return null;
}
}