Skip to content

Commit 54bde43

Browse files
authored
Merge pull request #1302 from sm9171/ver4/week3
[sm9171] Week 03 solutions
2 parents 8bc3990 + 68407bf commit 54bde43

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

number-of-1-bits/sm9171.java

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public static int hammingWeight(int n) {
2+
int sum = 0;
3+
while (n > 0) {
4+
sum += n % 2;
5+
n /= 2;
6+
}
7+
return sum;
8+
}

valid-palindrome/sm9171.java

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public boolean isPalindrome(String s) {
3+
String str = s.toLowerCase().replaceAll("[^a-z0-9]","");
4+
char[] charArray = str.toCharArray();
5+
for (int i = 0; i < charArray.length / 2; i++) {
6+
if (charArray[i] != charArray[charArray.length - i - 1]) {
7+
return false;
8+
}
9+
}
10+
return true;
11+
}
12+
}

0 commit comments

Comments
 (0)