Created
December 15, 2022 23:31
-
-
Save abdulrahmanAlotaibi/95abed6504b41330c15927a806cef390 to your computer and use it in GitHub Desktop.
Strings : First Unique Character in a String
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
func firstUniqChar(s string) int { | |
for i:= 0 ; i < len(s) ; i++ { | |
ch := string(s[i]) | |
isUnique := true | |
for j:= 0 ; j < len(s); j++ { | |
if j != i && string(s[j]) == ch { | |
isUnique = false | |
break | |
} | |
} | |
if isUnique { | |
return i | |
} | |
} | |
return -1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment