Skip to content

Commit db1cd17

Browse files
authored
Merge pull request #1898 from s0ooo0k/main
[s0ooo0k] WEEK8 Solution
2 parents 2278f9c + c035853 commit db1cd17

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

palindromic-substrings/s0ooo0k.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
// 팰린드롬의 경우 양쪽이 같아야 하므로, 중심을 잡고 left, right로 늘려나가는 방식
3+
public int countSubstrings(String s) {
4+
int cnt = 0;
5+
6+
for(int i=0; i<s.length(); i++) {
7+
cnt += palindrome(s, i, i);
8+
cnt += palindrome(s, i, i+1);
9+
}
10+
return cnt;
11+
}
12+
public static int palindrome(final String s, int left, int right) {
13+
int cnt = 0;
14+
while(left>=0 && right < s.length() && s.charAt(left)==s.charAt(right)) {
15+
cnt++;
16+
left--;
17+
right++;
18+
}
19+
return cnt;
20+
}
21+
}
22+

reverse-bits/s0ooo0k.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int reverseBits(int n) {
3+
int result = 0;
4+
for(int i = 0; i < 32; i++) {
5+
result <<= 1;
6+
result |= (n & 1);
7+
n >>>= 1;
8+
}
9+
return result;
10+
}
11+
}
12+

0 commit comments

Comments
 (0)