Skip to content

Instantly share code, notes, and snippets.

@jonbodner
Created July 1, 2014 19:20
Show Gist options
  • Save jonbodner/adb93a5f8652fea46eca to your computer and use it in GitHub Desktop.
Save jonbodner/adb93a5f8652fea46eca to your computer and use it in GitHub Desktop.
First non-repeated character in a string in Go
package main
import "fmt"
func firstNonRepeatChar(s string) rune {
useMap := make(map[rune]bool)
for _, v := range s {
_, ok := useMap[v]
useMap[v] = ok
}
for _, v := range s {
if !useMap[v] {
return v
}
}
return rune(0)
}
func main() {
fmt.Printf("%c",firstNonRepeatChar("abca"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment