-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update solutions to lc problems: No.2108,2109
* No.2108.Find First Palindromic String in the Array * No.2109.Adding Spaces to a String
- Loading branch information
Showing
9 changed files
with
73 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 9 additions & 10 deletions
19
solution/2100-2199/2108.Find First Palindromic String in the Array/Solution.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 3 additions & 13 deletions
16
solution/2100-2199/2108.Find First Palindromic String in the Array/Solution.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 1 addition & 15 deletions
16
solution/2100-2199/2108.Find First Palindromic String in the Array/Solution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,3 @@ | ||
function firstPalindrome(words: string[]): string { | ||
for (const word of words) { | ||
let left = 0; | ||
let right = word.length - 1; | ||
while (left < right) { | ||
if (word[left] !== word[right]) { | ||
break; | ||
} | ||
left++; | ||
right--; | ||
} | ||
if (left >= right) { | ||
return word; | ||
} | ||
} | ||
return ''; | ||
return words.find(w => w === w.split('').reverse().join('')) || ''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
solution/2100-2199/2109.Adding Spaces to a String/Solution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
function addSpaces(s: string, spaces: number[]): string { | ||
let ans = ''; | ||
const ans: string[] = []; | ||
for (let i = 0, j = 0; i < s.length; i++) { | ||
if (j < spaces.length && i === spaces[j]) { | ||
ans += ' '; | ||
++j; | ||
if (i === spaces[j]) { | ||
ans.push(' '); | ||
j++; | ||
} | ||
ans += s[i]; | ||
ans.push(s[i]); | ||
} | ||
return ans; | ||
return ans.join(''); | ||
} |
Oops, something went wrong.