Kaynağa Gözat

add z第一个只出现一次的字符

tangs 2 yıl önce
ebeveyn
işleme
f5ed394806

+ 34 - 0
leetcode/剑指offer/第一个只出现一次的字符/main.go

@@ -0,0 +1,34 @@
+package main
+
+import (
+	"bufio"
+	"fmt"
+	"os"
+)
+
+func main() {
+	var input = bufio.NewScanner(os.Stdin)
+	var output byte
+	for input.Scan() {
+		line := input.Text()
+
+		output = firstUniqChar(line)
+		fmt.Println(string(output))
+	}
+}
+
+func firstUniqChar(s string) byte {
+	var record = [26]int{}
+	for i := 0; i < len(s); i++ {
+		var key = s[i] - 'a'
+		record[key]++
+	}
+	for i := 0; i < len(s); i++ {
+		var key = s[i] - 'a'
+		if record[key] == 1 {
+			return s[i]
+		}
+	}
+
+	return ' '
+}