Created
May 1, 2024 16:09
-
-
Save lbvf50mobile/b61531c7ca9bdab7b7280e151c4285b6 to your computer and use it in GitHub Desktop.
Leetcode: 2000. Reverse Prefix of Word.
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
// Leetcode: 2000. Reverse Prefix of Word. | |
// https://leetcode.com/problems/reverse-prefix-of-word/ | |
// = = = = = = = = = = = = = = | |
// Accepted. | |
// Thanks God, Jesus Christ! | |
// = = = = = = = = = = = = = = | |
// Runtime: 1 ms, faster than 76.52% of Go online submissions for Reverse | |
// Prefix of Word. | |
// Memory Usage: 2.3 MB, less than 74.78% of Go online submissions for Reverse | |
// Prefix of Word. | |
// 2024.05.01 Daily Challenge. | |
package main | |
func reversePrefix(word string, ch byte) string { | |
bts := []byte(word) | |
i, j := 0, 0 | |
for i, v := range bts { | |
if v == ch { | |
j = i | |
break | |
} | |
} | |
for i < j { | |
bts[i], bts[j] = bts[j], bts[i] | |
i += 1 | |
j -= 1 | |
} | |
return string(bts) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment