There is a solution for leetcode task: 2215. Find the Difference of Two Arrays You need…
- User
There is a solution for leetcode task: 2215. Find the Difference of Two Arrays You need to analize it and make it more efficient and simple if possible
func findDifference(nums1 []int, nums2 []int) [][]int { hashMap1 := make(map[int]bool, len(nums1)) hashMap2 := make(map[int]bool, len(nums2)) result := make([][]int, 2) for _, val := range nums1 { hashMap1[val] = true } for _, val := range nums2 { hashMap2[val] = true } fmt.Println(hashMap1, hashMap2)
for key, _ := range hashMap2 { if hashMap1[key] != true { result[1] = append(result[1], key) } else { hashMap1[key] = false } } for key, _ := range hashMap1 { if hashMap1[key] == true { result[0] = append(result[0], key) } } return result}
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.