Skip to content

Commit 525a8a3

Browse files
authored
Merge branch 'DaleStudy:main' into main
2 parents acf9053 + 348ed81 commit 525a8a3

172 files changed

Lines changed: 3978 additions & 588 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
File renamed without changes.
File renamed without changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function maxProfit(prices: number[]): number {
2+
let minPrice = Number.MAX_SAFE_INTEGER;
3+
let maxProfit = 0;
4+
5+
for (let p of prices) {
6+
if (minPrice >= p) {
7+
minPrice = p;
8+
continue;
9+
} else {
10+
let profit = p - minPrice;
11+
if (profit > maxProfit) maxProfit = profit;
12+
}
13+
}
14+
return maxProfit;
15+
}
16+
17+
function maxProfit(prices: number[]): number {
18+
let minPrice = Infinity;
19+
let maxProfit = 0;
20+
21+
for (let p of prices) {
22+
minPrice = Math.min(minPrice, p);
23+
maxProfit = Math.max(maxProfit, p - minPrice);
24+
}
25+
return maxProfit;
26+
}
File renamed without changes.

best-time-to-buy-and-sell-stock/robinyoon-dev.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ var maxProfit = function (prices) {
2323
return maxProfit;
2424
};
2525

26-
2726
// -----아래는 이전에 작성한 답안입니다.
2827
// /**
2928
// * @param {number[]} prices
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
// 3rd tried
12
function maxProfit(prices: number[]): number {
2-
let minPrice = Infinity;
3-
let maxProfit = 0;
4-
for (let i = 0; i < prices.length; i++) {
5-
if (prices[i] < minPrice) {
6-
minPrice = prices[i];
7-
}
3+
let left = 0;
4+
let right = 1;
5+
let max = 0;
86

9-
if (prices[i] - minPrice > maxProfit) {
10-
maxProfit = prices[i] - minPrice;
11-
}
7+
while(left < right && right < prices.length) {
8+
if(prices[right] - prices[left] > 0) {
9+
max = Math.max(max, prices[right] - prices[left])
10+
} else {
11+
left = right;
12+
}
13+
right++;
1214
}
13-
return maxProfit;
14-
}
15+
return max;
16+
};

climbing-stairs/soobing.ts

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,14 @@
1-
/**
2-
* 문제 유형
3-
* - DP (피보나치)
4-
*
5-
* 문제 설명
6-
* - 계단을 올라가는 방법의 수를 구하기
7-
*
8-
* 아이디어
9-
* 1) 피보나치 수열 활용
10-
* - climbStairs(n) = climbStairs(n-1) + climbStairs(n-2)
11-
*/
12-
function climbStairsBottomUp(n: number): number {
13-
function fibonacci(n: number, memo = new Map<number, number>()) {
14-
if (n === 1) return 1;
15-
if (n === 2) return 2;
1+
function climbStairs(n: number): number {
2+
const memo = new Map<number, number>();
3+
4+
function dp (n: number): number {
5+
if(n <= 1) return 1;
6+
if(memo.has(n)) return memo.get(n)!;
167

17-
if (memo.has(n)) return memo.get(n);
18-
const result = fibonacci(n - 1, memo) + fibonacci(n - 2, memo);
19-
memo.set(n, result);
20-
return result;
8+
const result = dp(n-1) + dp(n-2);
9+
memo.set(n, result);
10+
return result;
2111
}
22-
return fibonacci(n);
23-
}
2412

25-
function climbStairsTopDown(n: number): number {
26-
const dp = new Array(n + 1).fill(0);
27-
dp[1] = 1;
28-
dp[2] = 2;
29-
30-
for (let i = 3; i <= n; i++) {
31-
dp[i] = dp[i - 1] + dp[i - 2];
32-
}
33-
return dp[n];
34-
}
13+
return dp(n);
14+
};

climbing-stairs/soobing3.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

clone-graph/Hyeri1ee.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import java.util.*;
2+
/*
3+
class Node {
4+
public int val;
5+
public List<Node> neighbors;
6+
public Node() {
7+
val = 0;
8+
neighbors = new ArrayList<Node>();
9+
}
10+
public Node(int _val) {
11+
val = _val;
12+
neighbors = new ArrayList<Node>();
13+
}
14+
public Node(int _val, ArrayList<Node> _neighbors) {
15+
val = _val;
16+
neighbors = _neighbors;
17+
}
18+
}
19+
*/
20+
21+
22+
class Solution {
23+
24+
25+
//기존 node, 복사한 node
26+
Map<Node, Node> visited = new HashMap<>();
27+
public Node cloneGraph(Node node) {
28+
if (node==null) return null;
29+
30+
if (visited.containsKey(node)){
31+
return visited.get(node);
32+
}
33+
34+
//없는 경우
35+
Node newClone= new Node(node.val);
36+
visited.put(node, newClone);
37+
38+
//이웃 복사
39+
for(Node target : node.neighbors){
40+
newClone.neighbors.add(cloneGraph(target));
41+
}
42+
43+
return newClone;
44+
45+
}
46+
}
47+
48+

0 commit comments

Comments
 (0)