Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
14 changes: 14 additions & 0 deletions contains-duplicate/oyeong011.cpp
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;
}
};
17 changes: 17 additions & 0 deletions house-robber/oyeong011.cpp
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];
}
};
21 changes: 21 additions & 0 deletions longest-consecutive-sequence/oyeong011.cpp
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;
}
};
21 changes: 21 additions & 0 deletions top-k-frequent-elements/oyeong011.cpp
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

풀이가 다른 문제와 중복되어 있는 것 같습니다. 확인을 부탁 드립니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵 수정했습니다!

};
16 changes: 16 additions & 0 deletions valid-palindrome/oyeong011.cpp
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;
}
};
Loading