-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1365HowManyNumbersAreSmallerThantheCurrentNumber.cs
More file actions
84 lines (67 loc) · 1.93 KB
/
1365HowManyNumbersAreSmallerThantheCurrentNumber.cs
File metadata and controls
84 lines (67 loc) · 1.93 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CodeForecs
{
public class CustomComparer : IComparer<CustomObject>
{
int IComparer<CustomObject>.Compare(CustomObject x, CustomObject y)
{
if(x.Value < y.Value)
{
y.NumbersSmaller += 1;
}
else if(x.Value > y.Value)
{
x.NumbersSmaller += 1;
}
return 0;
}
}
public class CustomObject
{
public int Value { get; set; }
public int Index { get; set; }
public int NumbersSmaller { get; set; }
public CustomObject(int x, int y)
{
Value = x;
Index = y;
}
}
public class _1365HowManyNumbersAreSmallerThantheCurrentNumber
{
public int[] SmallerNumbersThanCurrent(int[] nums)
{
//int size = nums.Length;
//CustomObject[] arr = new CustomObject[size];
//for(int i = 0; i < size; i++)
//{
// arr[i] = new CustomObject(nums[i], i);
//}
//Array.Sort(arr, new CustomComparer());
//int[] answer = new int[size];
//var final = arr.Zip(answer, Tuple.Create);
//foreach (var nw in arr.Zip(answer, Tuple.Create))
//{
// nw.Item2 = nw.Item1.NumbersSmaller;
//}
int size = nums.Length;
int[] answer = new int[size];
for(int i = 0; i < size; i++)
{
int total = 0;
for(int j = 0; j < size; j++)
{
if(nums[j] < nums[i])
{
total += 1;
}
}
answer[i] = total;
}
return answer;
}
}
}