Skip to content

Commit b37f8ee

Browse files
committed
feat: valid-palindrome solve
1 parent 5f15293 commit b37f8ee

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

contains-duplicate/Real-Reason.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package leetcode_study
22

3-
class Solution {
3+
class SolutionContainsDuplicate {
44
fun containsDuplicate(nums: IntArray): Boolean {
55
val size = nums.size
66
val numsToSet = nums.toSet()
77

88
return size != numsToSet.size
99
}
10-
}
10+
}

valid-palindrome/Real-Reason.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package leetcode_study
2+
3+
class SolutionValidPalindrome {
4+
fun isPalindrome(s: String): Boolean {
5+
val sToCharArray = s.toCharArray()
6+
var startIndex = 0
7+
var endIndex = sToCharArray.size - 1
8+
while (startIndex < endIndex) {
9+
if (!sToCharArray[startIndex].isLetterOrDigit() || sToCharArray[startIndex].isWhitespace()) {
10+
startIndex++
11+
continue
12+
}
13+
if (!sToCharArray[endIndex].isLetterOrDigit() || sToCharArray[endIndex].isWhitespace()) {
14+
endIndex--
15+
continue
16+
}
17+
if (sToCharArray[startIndex].lowercase() == sToCharArray[endIndex].lowercase()) {
18+
startIndex++
19+
endIndex--
20+
} else {
21+
return false
22+
}
23+
}
24+
25+
return true
26+
}
27+
}

0 commit comments

Comments
 (0)