-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1460-Make-two-arrays-equal-by-reversing-sub-arrays.cs
More file actions
58 lines (49 loc) · 1.53 KB
/
Copy path1460-Make-two-arrays-equal-by-reversing-sub-arrays.cs
File metadata and controls
58 lines (49 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.Text;
namespace Solution._1460.Make_two_arrays_equal_by_reversing_sub_arrays
{
public class _1460_Make_two_arrays_equal_by_reversing_sub_arrays
{
public bool CanBeEqual(int[] target, int[] arr)
{
Dictionary<int, int> dic = new Dictionary<int, int>();
foreach (var i in target)
{
if (dic.ContainsKey(i))
dic[i]++;
else
dic.Add(i, 1);
}
foreach (var j in arr)
{
if (!dic.ContainsKey(j))
return false;
else if (dic[j] == 0)
return false;
else
dic[j]--;
}
//for (int i = 0; i < target.Length; i++)
//{
// // target
// if (dic.ContainsKey(target[i]))
// dic[target[i]]++;
// else
// dic.Add(target[i], 1);
// // arr
// if (dic.ContainsKey(arr[i]))
// dic[arr[i]]--;
// else
// dic.Add(arr[i], -1);
// // remove
// if (dic[target[i]] == 0)
// dic.Remove(target[i]);
// if (dic.ContainsKey(arr[i]) && dic[arr[i]] == 0)
// dic.Remove(arr[i]);
//}
//return true;
return dic.Count == 0;
}
}
}