public class Solution {class KeyPoint {public int key;
public int height;
Public KeyPoint next = null;
public KeyPoint (int key, int height) {this.key = key;
This.height = height;
} public static int[] Getkeypoint (int key, int height) {int[] kp = new int[2];
Kp[0] = key;
KP[1] = height;
return KP;
List<int[]> getskyline (int[][] buildings) {KeyPoint head = new KeyPoint ( -1,0);
KeyPoint PREVKP = head;
For (int[] building:buildings) {int L = building[0], r = building[1], h= building[2];
Insert left point while (Prevkp.next!= null && prevKP.next.key <= l) PREVKP = Prevkp.next;
int preheight = Prevkp.height;
if (Prevkp.key = = L) prevkp.height = Math.max (Prevkp.height, h); else if (Prevkp.height < h) {KeyPoint next = Prevkp.nexT
Prevkp.next = new KeyPoint (l, h);
PREVKP = Prevkp.next;
Prevkp.next = Next;
}//Insert right point and update points in between KeyPoint prev = PREVKP, cur = prevkp.next;
while (cur!= null && Cur.key < r) {preheight = Cur.height;
Cur.height = Math.max (Cur.height, h);
if (cur.height = = prev.height) Prev.next = Cur.next;
else prev = cur;
cur = cur.next;
} if (Prev.height!= preheight && prev.key!= r && (cur = null | | Cur.key!= r)) {
KeyPoint next = Prev.next;
Prev.next = new KeyPoint (r, Preheight);
Prev.next.next = Next;
}//Convert to list<int[]> list<int[]> List = new arraylist<int[]> (); KeyPoint prev =Head, cur = head.next; while (cur!= null) {if (cur.height!= prev.height) list.add (Getkeypoint (Cur.key, Cur.height)
);
prev = cur;
cur = cur.next;
} return list; }
}