-
-
Notifications
You must be signed in to change notification settings - Fork 245
[oyeong011] Week 1 #642
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
[oyeong011] Week 1 #642
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1c65b02
contains duplicate sol
oyeong011 9bc5e4e
valid palindrome sol
oyeong011 5ffa46d
top-k-frequent-elements
oyeong011 f202799
house-robber sol
oyeong011 6322e95
longest consecutive sequence sol
oyeong011 0e5bb59
Merge remote-tracking branch 'origin/main'
oyeong011 88165ec
개행 문자 추가
oyeong011 7785c45
top-k-frequent sol
oyeong011 c718600
Merge branch 'DaleStudy:main' into main
oyeong011 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,14 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
class Solution { | ||
public: | ||
bool containsDuplicate(vector<int>& nums) { | ||
unordered_map<int, int> mp; | ||
for(int a : nums){ | ||
if(++mp[a] >= 2){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
}; |
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,17 @@ | ||
class Solution { | ||
public: | ||
int rob(vector<int>& nums) { | ||
int n = nums.size(); | ||
if(n == 0)return 0; | ||
if(n == 1)return nums[0]; | ||
if(n == 2)return max(nums[0], nums[1]); | ||
|
||
vector<int> dp(n); | ||
dp[0] = nums[0]; | ||
dp[1] = max(nums[0], nums[1]); | ||
for(int i = 2; i < n; i++){ | ||
dp[i] = max(dp[i - 1], dp[i - 2] + nums[i]); | ||
} | ||
return dp[n - 1]; | ||
} | ||
}; |
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,21 @@ | ||
class Solution { | ||
public: | ||
int longestConsecutive(vector<int>& nums) { | ||
const int INF = 987654321; | ||
int temp = INF, ret = 0, cur = 0; | ||
|
||
sort(nums.begin(), nums.end()); | ||
for(int a : nums){ | ||
if(a == temp)continue; | ||
if(temp == INF || temp + 1 == a){ | ||
cur++; temp = a; | ||
} else { | ||
ret = max(ret, cur); | ||
cur = 1; | ||
temp = a; | ||
} | ||
} | ||
ret = max(ret, cur); | ||
return ret; | ||
} | ||
}; |
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,21 @@ | ||
class Solution { | ||
public: | ||
int longestConsecutive(vector<int>& nums) { | ||
const int INF = 987654321; | ||
int temp = INF, ret = 0, cur = 0; | ||
|
||
sort(nums.begin(), nums.end()); | ||
for(int a : nums){ | ||
if(a == temp)continue; | ||
if(temp == INF || temp + 1 == a){ | ||
cur++; temp = a; | ||
} else { | ||
ret = max(ret, cur); | ||
cur = 1; | ||
temp = a; | ||
} | ||
} | ||
ret = max(ret, cur); | ||
return ret; | ||
} | ||
}; |
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,16 @@ | ||
class Solution { | ||
public: | ||
bool isPalindrome(string s) { | ||
string clean = ""; | ||
for(char c : s) { | ||
if(isalnum(c)) { | ||
clean += tolower(c); | ||
} | ||
} | ||
|
||
string reversed = clean; | ||
reverse(reversed.begin(), reversed.end()); | ||
|
||
return clean == reversed; | ||
} | ||
}; |
Oops, something went wrong.
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.
풀이가 다른 문제와 중복되어 있는 것 같습니다. 확인을 부탁 드립니다.
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.
넵 수정했습니다!