Leetcode Note: Go - Make Two Arrays Equal by Reversing Subarrays

Add Binary - LeetCode
https://leetcode.com/problems/add-binary/

  • Go 言語で取り組んだメモ

回答

Go solution - Make Two Arrays Equal by Reversing Subarrays - LeetCode
https://leetcode.com/problems/make-two-arrays-equal-by-reversing-subarrays/solutions/1861481/go-solution/

func canBeEqual(target []int, arr []int) bool {
	m, n := len(arr), len(target)
	if m != n {
		return false
	}

	mp := make(map[int]int)
	for i := 0; i < m; i++ {
		mp[target[i]]++
		mp[arr[i]]--
	}

	for _, v := range mp {
		if v != 0 {
			return false
		}
	}

	return true
}