Skip to content

Commit f0389b2

Browse files
authoredFeb 9, 2025
Merge pull request #990 from mintheon/main
[mintheon] Week 09
2 parents 87ce663 + 71da372 commit f0389b2

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
// 시간복잡도: O(n)
3+
// 공간복잡도: O(1)
4+
public int findMin(int[] nums) {
5+
for(int i = 1; i < nums.length; i++) {
6+
if(nums[i - 1] > nums[i]) {
7+
return nums[i];
8+
}
9+
}
10+
11+
return nums[0];
12+
}
13+
}

‎linked-list-cycle/mintheon.java

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* class ListNode {
4+
* int val;
5+
* ListNode next;
6+
* ListNode(int x) {
7+
* val = x;
8+
* next = null;
9+
* }
10+
* }
11+
*/
12+
//시간복잡도: O(n)
13+
//공간복잡도: O(1)
14+
public class Solution {
15+
public boolean hasCycle(ListNode head) {
16+
ListNode slow = head;
17+
ListNode fast = head;
18+
19+
while(fast != null && fast.next != null) {
20+
slow = slow.next;
21+
fast = fast.next.next;
22+
23+
if(slow == fast) return true;
24+
}
25+
26+
return false;
27+
}
28+
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution {
2+
//시간복잡도: O(n)
3+
//공간복잡도: O(n)
4+
public int maxProduct(int[] nums) {
5+
int[] maxValue = new int[nums.length];
6+
int[] minValue = new int[nums.length];
7+
8+
maxValue[0] = nums[0];
9+
minValue[0] = nums[0];
10+
11+
for(int i = 1; i < nums.length; i++) {
12+
int value1 = maxValue[i - 1] * nums[i];
13+
int value2 = minValue[i - 1] * nums[i];
14+
15+
maxValue[i] = Math.max(Math.max(value1, value2), nums[i]);
16+
minValue[i] = Math.min(Math.min(value1, value2), nums[i]);
17+
}
18+
19+
int result = Integer.MIN_VALUE;
20+
for(int i = 0; i < nums.length; i++) {
21+
result = Math.max(result, maxValue[i]);
22+
}
23+
24+
return result;
25+
}
26+
}

0 commit comments

Comments
 (0)
Please sign in to comment.