A golang solution


  • 0
    N
    type strInfo struct {
    	s string
    	l int
    	m map[rune]int
    }
    
    func isAnagram(s string, t string) bool {
    	var array [2]strInfo
    	
    	for i, v := range []string{s, t} {
    		array[i].s = v
    		array[i].m = make(map[rune]int)
    		for _, v := range array[i].s {
    			array[i].l++
    			array[i].m[v]++
    		}
    	}
    	
    	if array[0].l != array[1].l {
    		return false
    	}
    
    	for k0, v0 := range array[0].m {
    		if v1, ok := array[1].m[k0]; !ok || v0 != v1 {
    			return false
    		}
    	}
    	return true
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.