Skip to content

Commit 590313c

Browse files
authored
Merge pull request #1777 from mumunuu/main
[mumunuu] WEEK 02 solutions
2 parents e845a44 + 3e16096 commit 590313c

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

climbing-stairs/mumunuu.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// 70. Climbing Stairs https://leetcode.com/problems/climbing-stairs/description/
2+
class Solution {
3+
public int climbStairs(int n) {
4+
5+
6+
if (n <= 2) {
7+
return n;
8+
}
9+
10+
int a = 1;
11+
int b = 2;
12+
13+
for (int i = 3; i <= n; i++) {
14+
int temp = b;
15+
b = a + b;
16+
a = temp;
17+
}
18+
19+
return b;
20+
21+
22+
}
23+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Solution {
2+
public int[] productExceptSelf(int[] nums) {
3+
4+
// 원래는 그냥 다 곱해서 자기 빼고 나누면 되는데 나눗셈 하지 말라고 함
5+
6+
// 왼쪽 곱 구한다음에 오른쪽 곱으로 리턴하면 됨
7+
int[] answer = new int[nums.length];
8+
9+
int left = 1;
10+
answer[0] = left;
11+
12+
for (int i = 1; i < nums.length; i++) {
13+
answer[i] = answer[i - 1] * nums[i - 1];
14+
}
15+
16+
// 1 1 2 6
17+
18+
// 오른쪽 누적 곱
19+
20+
int right = 1;
21+
22+
for (int i = nums.length - 1; i >= 0; i--) {
23+
answer[i] = answer[i] * right;
24+
right *= nums[i];
25+
}
26+
27+
28+
return answer;
29+
30+
}
31+
}

valid-anagram/mumunuu.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java.util.Arrays;
2+
3+
class Solution {
4+
public boolean isAnagram(String s, String t) {
5+
6+
if (s.length() != t.length()) {
7+
return false;
8+
}
9+
10+
char[] a = s.toCharArray();
11+
char[] b = t.toCharArray();
12+
13+
Arrays.sort(a);
14+
Arrays.sort(b);
15+
16+
return Arrays.equals(a, b);
17+
18+
}
19+
}

0 commit comments

Comments
 (0)