File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments