Skip to content

Commit 0b222f1

Browse files
Merge pull request #2116 from kimjunyoung90/main
[kimjunyoung90] WEEK 03 solutions
2 parents a519017 + 4a2c349 commit 0b222f1

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* μ‹œκ°„λ³΅μž‘λ„ : O(n)
3+
* κ³΅κ°„λ³΅μž‘λ„ : O(n)
4+
*/
5+
public class kimjunyoung90 {
6+
public boolean isPalindrome(String s) {
7+
//1. λŒ€λ¬Έμžλ₯Ό μ†Œλ¬Έμžλ‘œ λ³€ν™˜
8+
s = s.toLowerCase();
9+
10+
//2. μ˜μ–΄ 숫자 μ™Έ 문자 제거
11+
s = s.replaceAll("[^a-z0-9]", "");
12+
13+
//3. μ•žμ—μ„œ μ½λ‚˜ λ’€μ—μ„œ μ½λ‚˜ λ™μΌν•œμ§€ 확인(pointer μ‚¬μš©)
14+
int left = 0, right = s.length() - 1;
15+
while(left < right) {
16+
char leftChar = s.charAt(left);
17+
char rightChar = s.charAt(right);
18+
if(leftChar != rightChar) return false;
19+
left++;
20+
right--;
21+
}
22+
return true;
23+
}
24+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class Solution {
2+
public int maxSubArray(int[] nums) {
3+
int max = Integer.MIN_VALUE;
4+
for(int i = 0; i < nums.length; i++) {
5+
for (int j = i; j < nums.length; j++) {
6+
int sum = 0;
7+
for(int k = i; k <= j; k++) {
8+
sum+= nums[k];
9+
}
10+
max = Math.max(max, sum);
11+
}
12+
}
13+
return max;
14+
}
15+
}

0 commit comments

Comments
Β (0)