-
-
Notifications
You must be signed in to change notification settings - Fork 244
[crumbs22] WEEK 1 #1188
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
Merged
Merged
[crumbs22] WEEK 1 #1188
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
935bc37
FEAT : upload #217
crumbs22 13719f3
CHORE : add a newline
crumbs22 b155433
FEAT : upload #219
crumbs22 3337224
FEAT : upload #237.cpp
crumbs22 09bab7e
FEAT : solve #128
crumbs22 9437c60
FEAT : solve #264
crumbs22 b8b3e5f
FEAT : add comment
crumbs22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <unordered_set> | ||
|
||
using namespace std; | ||
|
||
class Solution { | ||
public: | ||
bool containsDuplicate(vector<int>& nums) { | ||
unordered_set<int> uset(nums.begin(), nums.end()); | ||
return (nums.size() != uset.size()); | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
bool cmp(const pair<int, int>& a, const pair<int, int>& b) | ||
{ | ||
if (a.second == b.second) | ||
return a.first < b.first; | ||
return a.second > b.second; | ||
} | ||
|
||
class Solution { | ||
public: | ||
vector<int> topKFrequent(vector<int>& nums, int k) { | ||
unordered_map<int, int> umap; | ||
|
||
for (int i = 0; i < nums.size(); i++) | ||
{ | ||
auto tmp = umap.find(nums[i]); | ||
if (tmp != umap.end()) | ||
tmp->second += 1; | ||
else | ||
umap.insert(make_pair(nums[i], 1)); | ||
} | ||
vector<pair<int,int>> vec(umap.begin(), umap.end()); // map을 vector로 이동 | ||
sort(vec.begin(), vec.end(), cmp); | ||
|
||
vector<int> result; | ||
for (int i = 0; i < k; i++) | ||
result.push_back(vec[i].first); | ||
return (result); | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
class Solution { | ||
public: | ||
vector<int> twoSum(vector<int>& nums, int target) { | ||
if (nums.size() == 2) | ||
return {1, 2}; | ||
int tmp; | ||
for (int i = 0; i < nums.size(); i++) | ||
{ | ||
tmp = target - nums[i]; | ||
for (int j = i + 1; j < nums.size(); j++) | ||
{ | ||
if (nums[j] == tmp) | ||
{ | ||
return {i, j}; | ||
} | ||
} | ||
} | ||
return {-1}; | ||
} | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
이중 for loop를 사용하고 있는데 여기서 해시맵을 사용해서 시간복잡도를 줄이는 방법을 생각해보면 좋을 것 같아요!
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.
리뷰 감사합니다! 다시 고려해서 풀어보도록 하겠습니다. 다음 주차도 화이팅!