Skip to content
Open
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
20 changes: 20 additions & 0 deletions 09월/1주차/[LCD] Best Time to Buy and Sell Stock/Min.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Min {
public int maxProfit(int[] prices) {
int min = 100001;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

문제에서 최대값을 파악하고 설정한 점이 인상깊었습니다!! 👍

int max = 0;
int profit = 0;
for(int i = 0; i < prices.length; i++) {
if(min > prices[i]) {
min = prices[i];
max = prices[i];
continue;
}
if(max < prices[i]) {
max = prices[i];
profit = Math.max(profit, max - min);
}
}

return profit;
}
}
31 changes: 31 additions & 0 deletions 09월/1주차/[LCD] Pascal's Triangle II/Min.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.util.*;

class Min {
public List<Integer> getRow(int rowIndex) {
List<Integer> answer = new ArrayList<>();
if(rowIndex == 0) {
answer.add(1);
return answer;
}
if(rowIndex == 1) {
answer.add(1);
answer.add(1);
return answer;
}

answer.add(1);
answer.add(1);

for(int i = 2; i <= rowIndex; i++) {
List<Integer> nextRow = new ArrayList<>();
nextRow.add(1);
for(int j = 0; j < answer.size() - 1; j++) {
nextRow.add(answer.get(j) + answer.get(j + 1));
}

nextRow.add(1);
answer = nextRow;
}
return answer;
}
}