Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution2
- {
- int distance(KeyValuePair<int,int> a, KeyValuePair<int, int> b)
- {
- if (a.Key == b.Key && a.Value == b.Value)
- return 0;
- var x1 = 0;
- var y1 = 0;
- var x2 = Math.Abs(b.Key - a.Key);
- var y2 = Math.Abs(b.Value - a.Value);
- if (x1 == x2)
- return y2;
- if (y1 == y2)
- return x2;
- return x2 + y2 - Math.Min(x2, y2);
- //return 1 + distance(new KeyValuePair<int, int>(1, 1), new KeyValuePair<int, int>(x2, y2));
- }
- public int coverPoints(List<int> A, List<int> B)
- {
- int idx = 0;
- int fullDistance = 0;
- while(idx < A.Count-1)
- {
- var a = new KeyValuePair<int, int>(A[idx], B[idx]);
- var b = new KeyValuePair<int, int>(A[idx+1], B[idx+1]);
- fullDistance += distance(a, b);
- idx++;
- }
- return fullDistance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement