Created
May 10, 2019 15:11
-
-
Save vivan-snapretail/d2fbca18e7f48b5fb636906297ef372b to your computer and use it in GitHub Desktop.
coderbyte alphabet soup
This file contains hidden or 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
package main | |
import "fmt" | |
import "sort" | |
type runeSorter []rune | |
func AlphabetSoup(str string) string { | |
// code goes here | |
sorted := SortString(str) | |
// Note: feel free to modify the return type of this function | |
return sorted | |
} | |
func SortString( s string) string { | |
r := []rune(s) | |
sort.Sort(runeSorter(r)) | |
return string(r) | |
} | |
func (s runeSorter) Swap(i, j int) { | |
s[i],s[j] = s[j],s[i] | |
} | |
func (s runeSorter) Less(i, j int) bool { | |
return s[i] < s[j] | |
} | |
func (s runeSorter) Len() int { | |
return len(s) | |
} | |
func main() { | |
// do not modify below here, readline is our function | |
// that properly reads in the input for you | |
fmt.Println(AlphabetSoup(readline())) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment