-
Notifications
You must be signed in to change notification settings - Fork 1
upload week1 #6
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
Open
su-lim
wants to merge
1
commit into
main
Choose a base branch
from
su-lim/week1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
upload week1 #6
Changes from all commits
Commits
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,35 @@ | ||
// 백준 - 가장 긴 바이토닉 부분 수열 | ||
|
||
const fs = require("fs"); | ||
const input = fs.readFileSync("/dev/stdin").toString().trim().split("\n"); | ||
const n =+input[0]; | ||
const numberList = input[1].split(" ").map((e) => +e); | ||
|
||
function main(N, numberList) { | ||
let answer = 0; | ||
|
||
const reverseNumberList = numberList.slice().reverse(); | ||
|
||
// k일 때, 증가 배열의 최대 수 / 감소 배열의 최대 수 저장 | ||
let increase = new Array(N).fill(1); | ||
let decrease = new Array(N).fill(1); | ||
|
||
for (let i = 0; i < N; i++) { | ||
for (let j = 0; j < i; j++) { | ||
if (numberList[i] > numberList[j]) { | ||
increase[i] = Math.max(increase[i], increase[j] + 1); | ||
} | ||
if (reverseNumberList[i] > reverseNumberList[j]) { | ||
decrease[i] = Math.max(decrease[i], decrease[j] + 1); | ||
} | ||
} | ||
} | ||
|
||
for (let i = 0; i < N; i++) { | ||
answer = Math.max(increase[i] + decrease[N - i - 1] - 1, answer); | ||
} | ||
return answer; | ||
} | ||
|
||
const answer = main(n, numberList); | ||
console.log(answer); |
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,32 @@ | ||
// 백준 - 회의실 배정 | ||
|
||
const fs = require("fs"); | ||
const input = fs.readFileSync("/dev/stdin").toString().trim().split("\n"); | ||
const N = +input[0]; | ||
let timeList = []; | ||
|
||
for(let i=1;i<N+1;i++){ | ||
timeList.push(input[i].split(" ").map((e) => +e)); | ||
} | ||
|
||
function main(N, timeList) { | ||
let count = 0; | ||
let startTime = 0; | ||
|
||
timeList.sort(function(a,b){ | ||
return a[0] - b[0]; | ||
}) | ||
timeList.sort(function(a,b){ | ||
return a[1] - b[1]; | ||
}) | ||
Comment on lines
+16
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. compare function을 하나로 적으면 더 간단해질 것 같아요. (대충 로직은 알고 있을 거라고 생각하니까 arrow function 형태로 적었습니다.) const compareFunction = (a, b) => (a[0] - b[0] !== 0 ? a[0] - b[0] : a[1] - b[1]) |
||
|
||
for(let i=0;i<timeList.length;i++){ | ||
if(timeList[i][0] >= startTime){ | ||
count += 1; | ||
startTime = timeList[i][1]; | ||
} | ||
} | ||
return count; | ||
} | ||
|
||
console.log(main(N, timeList)); |
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,34 @@ | ||
// 백준 - 부분합 | ||
|
||
const fs = require("fs"); | ||
const input = fs.readFileSync("/dev/stdin").toString().trim().split("\n"); | ||
const [N, S] = input[0].split(" ").map((e)=> +e); | ||
const sequence = input[1].split(" ").map((e) => +e); | ||
|
||
let [L, R] = [0, 0]; | ||
let MAX_SIZE = 100000; | ||
let size = MAX_SIZE; | ||
let sum = 0; | ||
|
||
while( R !== N ){ | ||
|
||
// L부터 R까지 합 구하기 | ||
sum = 0; | ||
for(let i=L; i<R+1; i++){ | ||
sum += sequence[i]; | ||
} | ||
|
||
if(sum >= S){ | ||
size = R-L+1; | ||
if(size === 1) break; | ||
L += 1; | ||
} | ||
else{ | ||
R += 1; | ||
if(size <= R-L+1){ | ||
L += 1; | ||
} | ||
} | ||
|
||
} | ||
console.log(size === MAX_SIZE ? 0 : size); |
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.
main으로 구분지어 주는 것도 좋아보이네요. 대부분의 코테 플랫폼도 solution 형태로 코드를 작성하도록 되어있다보니 연습도 할 겸 좋은 것 같아요!