File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed
Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .*;
2+
3+
4+ class Solution {
5+ public int hammingWeight (int n ) {
6+
7+ int answer =0 ;
8+ while (n > 0 ){
9+ if ((n & 1 ) == 1 ){
10+ answer ++;
11+
12+ }
13+ n >>>= 1 ;//unsigned shift
14+
15+ }
16+
17+ return answer ;
18+
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ import java .util .*;
2+
3+ //palindrome
4+ class Solution {
5+ public boolean isPalindrome (String s ) {
6+
7+ ArrayList <Character > list = new ArrayList <>();
8+ //list에 넣기
9+ for (int i = 0 ; i < s .length (); i ++) {
10+ char c = s .charAt (i );
11+
12+ if (!Character .isLetterOrDigit (c ))
13+ continue ;
14+
15+ list .add (c );
16+ }
17+
18+ System .out .println (list .size ());
19+
20+ boolean ok = true ;
21+ int start = 0 ;
22+ int end = list .size () - 1 ;
23+
24+ if (list .size () == 0 || list .size () == 1 )
25+ return true ;
26+
27+ //디버깅
28+ for (int i = 0 ; i < list .size (); i ++) {
29+ System .out .println (list .get (i ));
30+ }
31+
32+ while (start < end ) {
33+ if (Character .toLowerCase (list .get (start )) !=
34+ Character .toLowerCase (list .get (end ))) {
35+ return false ;
36+ }
37+
38+ start ++;end --;
39+ } //end of while
40+
41+ return ok ;
42+ }
43+
44+ private static boolean isInRange (char c ) {
45+ return (c >= 'A' ) && (c <= 'Z' ) || (c >= 'a' ) && (c <= 'z' );
46+ }
47+
48+ }
You can’t perform that action at this time.
0 commit comments