1046. Last Stone Weight

1046. Last Stone Weight

class Solution {
      public int lastStoneWeight(int[] stones) {
    	PriorityQueue queue = new PriorityQueue(new Comparator() {                                                                                      @Override 
    		public int compare(Integer o1, Integer o2) {       
    		return - Integer.compare(o1,o2); } });
    
    	for (int i = 0; i = 2) {
    		int x = queue.poll();
    		int y = queue.poll();
    		if (x == y) continue;
    		if ( x <= y && x != y) queue.offer(y-x);
    		else if( y 0 ?queue.poll():0;
}}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s