Golang Leetcode 389. Find the Difference.go

思路

还是用hash表的方式处理

code

func findTheDifference(s string, t string) byte {

	m := make(map[int32]int, 256)

	var i int32
	for i = 0; i < 256; i++ {
		m[i] = 0
	}

	for _, v := range s {
		m[v]++
	}
	for _, v := range t {
		m[v]--
		if m[v] < 0 {
			return byte(v)
		}
	}
	return 0
}

更多内容请移步我的repo:https://github.com/anakin/golang-leetcode

你可能感兴趣的:(leetcode-golang,golang,leetcode,算法)