Skip to content
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

1-g0rnn #4

Merged
merged 1 commit into from
Oct 1, 2024
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
19 changes: 19 additions & 0 deletions g0rnn/DFS,BFS/4-g0rnn3.cpp
Copy link
Collaborator

Choose a reason for hiding this comment

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

μž¬κ·€λ₯Ό μ‚¬μš©ν•œ dfsμ½”λ“œ 잘 λ΄€μŠ΅λ‹ˆλ‹€.
λ§μ”€ν•˜μ‹ λŒ€λ‘œ μž¬κ·€μ—μ„œλŠ” basecaseλ₯Ό 잘 μ„€μ •ν•˜λŠ” 것이 μ€‘μš”ν•œ 것 κ°™μŠ΅λ‹ˆλ‹€.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <string>
#include <vector>

using namespace std;

int dfs(vector<int>& numbers, int target, int i, int value) {
if(numbers.size() <= i) {
return (target == value) ? 1 : 0;
}

return dfs(numbers, target, i+1, value + numbers[i])
+ dfs(numbers, target, i+1, value - numbers[i]);
}

int solution(vector<int> numbers, int target) {
return dfs(numbers, target, 0, 0);
}


19 changes: 19 additions & 0 deletions g0rnn/μŠ€νƒ,큐/4-g0rnn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <vector>
#include <iostream>

using namespace std;

vector<int> solution(vector<int> arr)
{
vector<int> answer;

answer.push_back(arr[0]);

for(int i=1; i<arr.size(); i++) {
if(arr[i-1] != arr[i]) {
answer.push_back(arr[i]);
}
}

return answer;
}
30 changes: 30 additions & 0 deletions g0rnn/μŠ€νƒ,큐/4-g0rnn2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <string>
#include <vector>
#include <cmath>

using namespace std;

vector<int> solution(vector<int> progresses, vector<int> speeds) {
vector<int> answer;
vector<int> days;

for(int i=0; i<progresses.size(); i++) {
int day = ceil((100 - progresses[i]) / (double)speeds[i]);
days.push_back(day);
}

int cur_max = days[0];
int cnt = 1;

for(int i=1; i<days.size(); i++) {
if(cur_max >= days[i]) cnt++;
else {
answer.push_back(cnt);
cur_max = days[i];
cnt = 1;
}
}
answer.push_back(cnt);

return answer;
}