Skip to content

Commit f90a3fc

Browse files
committed
1544. Make The String Great
1 parent a6b7111 commit f90a3fc

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Make The String Great/kata.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package kata
2+
3+
func makeGood(s string) string {
4+
var stack []byte
5+
for i := 0; i < len(s); i++ {
6+
if s[i] >= 'a' && s[i] <= 'z' {
7+
if len(stack) > 0 && stack[len(stack)-1] >= 'A' && stack[len(stack)-1] <= 'Z' {
8+
if (stack[len(stack)-1] + 32) == s[i] {
9+
stack = stack[:len(stack)-1]
10+
continue
11+
}
12+
stack = append(stack, s[i])
13+
continue
14+
}
15+
stack = append(stack, s[i])
16+
} else {
17+
if len(stack) > 0 && stack[len(stack)-1] == (s[i]+32) {
18+
stack = stack[:len(stack)-1]
19+
continue
20+
}
21+
stack = append(stack, s[i])
22+
}
23+
}
24+
return string(stack)
25+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy