Skip to content
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
23 changes: 23 additions & 0 deletions climbing-stairs/mumunuu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 70. Climbing Stairs https://leetcode.com/problems/climbing-stairs/description/
class Solution {
public int climbStairs(int n) {


if (n <= 2) {
return n;
}

int a = 1;
int b = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

O(n) space DP를 변수 두 개를 이용해 O(1) space로 최적화하신 점이 인상깊습니다!


for (int i = 3; i <= n; i++) {
int temp = b;
b = a + b;
a = temp;
}

return b;


}
}
31 changes: 31 additions & 0 deletions product-of-array-except-self/mumunuu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Solution {
public int[] productExceptSelf(int[] nums) {

// 원래는 그냥 다 곱해서 자기 빼고 나누면 되는데 나눗셈 하지 말라고 함

// 왼쪽 곱 구한다음에 오른쪽 곱으로 리턴하면 됨
int[] answer = new int[nums.length];

int left = 1;
answer[0] = left;
Copy link
Contributor

Choose a reason for hiding this comment

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

left 변수는 answer[0]에 할당할 때 외에는 사용되지 않기 때문에 해당 변수를 삭제하고 answer[0] = 1로 할당해도 좋을 것 같아요~!


for (int i = 1; i < nums.length; i++) {
answer[i] = answer[i - 1] * nums[i - 1];
}

// 1 1 2 6

// 오른쪽 누적 곱

int right = 1;

for (int i = nums.length - 1; i >= 0; i--) {
answer[i] = answer[i] * right;
right *= nums[i];
}


return answer;

}
}
19 changes: 19 additions & 0 deletions valid-anagram/mumunuu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.util.Arrays;

class Solution {
public boolean isAnagram(String s, String t) {

if (s.length() != t.length()) {
return false;
}

char[] a = s.toCharArray();
char[] b = t.toCharArray();

Arrays.sort(a);
Arrays.sort(b);

return Arrays.equals(a, b);

}
}