C# solution


  • 2
    P
    List<Tuple<int, int>> temp = new List<Tuple<int, int>>();
                List<Tuple<int, int>> temp2 = new List<Tuple<int, int>>(people.GetLength(0));
                for (int k = 0; k < people.GetLength(0); k++)
                {
                    temp.Add(new Tuple<int, int>(people[k, 0], people[k, 1]));
                }
                //sort the numbers first by height and then by the position. height in descending order and position in ascending order.
                temp.Sort((x, y) => { int result = y.Item1.CompareTo(x.Item1); return result == 0 ? x.Item2.CompareTo(y.Item2) : result; });
                for (int i = 0; i < temp.Count; i++)
                {
                    temp2.Insert(temp[i].Item2, temp[i]);
                }
                for (int l = 0; l < people.GetLength(0); l++)
                {
                    people[l, 0] = temp2[l].Item1;
                    people[l, 1] = temp2[l].Item2;
                }
                //place the result back in original 2d array
                return people;
    

  • 0

    By far this is the greatest C# solution


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.