Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions 3sum/mkwkw.cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

@SamTheKorean 이 파일처럼 비었지만 Merge 된 경우가 더 있네요: #1756 (comment)

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//set-up
20 changes: 20 additions & 0 deletions climbing-stairs/mkwkw.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//Dynamic Programming
//dp[n] = dp[n-1]+dp[n-2]
class Solution {
public:
int climbStairs(int n) {
int dp[46];

dp[0] = 0;
dp[1] = 1;
dp[2] = 2;

for(int i=3; i<=n; i++)
Comment on lines +10 to +12
Copy link
Contributor

Choose a reason for hiding this comment

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

dp[2]를 초기화하지 않고 i=2부터 시작해도 되겠군요.

{
dp[i] = dp[i-1]+dp[i-2];
}

return dp[n];

}
};
1 change: 1 addition & 0 deletions product-of-array-except-self/mkwkw.cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

@SamTheKorean 이 파일처럼 비었지만 Merge 된 경우가 더 있네요: #1756 (comment)

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//set-up
37 changes: 37 additions & 0 deletions valid-anagram/mkwkw.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//map: key:alphabet, value:count
//if t is an anagram of s
// 1. same length
// 2. same content of map
class Solution {
public:
bool isAnagram(string s, string t) {

//1. different length -> false
if(s.length()!=t.length())
{
return false;
}

//2. different map -> false
map<char, int> sMap, tMap;
Copy link
Contributor

Choose a reason for hiding this comment

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

배열이나 unordered_map을 사용할 수도 있겠군요.

for(int i=0; i<s.length(); i++)
{
sMap[s[i]]++;
tMap[t[i]]++;
}

for(auto c : sMap)
{
if(tMap.find(c.first)==tMap.end())
{
return false;
}
if(tMap[c.first] != c.second)
{
return false;
}
}

return true;
}
};
81 changes: 81 additions & 0 deletions validate-binary-search-tree/mkwkw.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//Optimize complexity
Copy link
Contributor

Choose a reason for hiding this comment

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

아래 Division 풀이의 시간 복잡도와 공간 복잡도에 비해 더 최적화된 점이 없지 않나요?

class Solution {
public:
vector<int> productExceptSelf(vector<int>& nums) {

vector<int> answer(nums.size(), 1);
//production before nums[i] from index 0
int before = 1;

for(int i=0; i<nums.size()-1; i++)
{
before *= nums[i];
answer[i+1] *= before;
}

//nums[i] 기준 앞에서 production 해놓은 것에 nums[i] 기준 뒤에 것들을 production from index n-1
//production after nums[i] to answer[i-1]
// answer[i-1] * after
int after = 1;
for(int i=nums.size()-1; i>0; i--)
{
after *= nums[i];
answer[i-1] *= after;
}

return answer;
}
};



//using division operation
/*
class Solution {
public:
vector<int> productExceptSelf(vector<int>& nums) {
int zeroCnt = 0;
int allProduct = 1;
vector<int> answer(nums.size());

for(int i=0; i<nums.size(); i++)
{
allProduct *= nums[i];
if(nums[i]==0)
{
zeroCnt++;
}
}

if(zeroCnt == 0)
{
for(int i=0; i<nums.size(); i++)
{
answer[i] = allProduct/nums[i];
}
}
else if(zeroCnt == 1)
{
int zeroIdx = 0;
int allProductWithoutZero = 1;

for(int i=0; i<nums.size(); i++)
{
if(nums[i]==0)
{
zeroIdx = i;
}
else
{
allProductWithoutZero *=nums[i];
answer[i] = 0;
}
}

answer[zeroIdx] = allProductWithoutZero;
}

return answer;
}
};
*/