标签:system void highlight ide path this ble for add
package com.Long; import java.util.PriorityQueue; import java.util.Queue; import java.util.Random; class node implements Comparable<node>{ int val; int Index; @Override public int compareTo(node arg0) { if(this.val > arg0.val)return 1; if(this.val < arg0.val)return -1; return 0; } } class Solution{ private int arr[]; private int maxLength[]; private node data[]; private Queue<node> pq; public boolean LongPath(){ for(int i=1;i<arr.length;++i) { for(int j=0;j<i;++j) { if(arr[i]>arr[j]) { maxLength[i]=Math.max(maxLength[i],maxLength[j]+1); } } } return true; } public Solution(int Length) { arr=new int[Length]; maxLength=new int[Length]; data=new node[Length]; pq=new PriorityQueue<node>(Length); Random r=new Random(); for(int i=0;i<Length;++i) { arr[i]=r.nextInt(10); maxLength[i]=1; node temp=new node(); data[i]=temp; } } public boolean printPath() { for(int i=0;i<arr.length;++i) { data[i].val=maxLength[i]; data[i].Index=i; } return true; } public boolean pushQueue() { for(int i=0;i<arr.length-1;++i) { if(maxLength[i]<=maxLength[i+1]) { pq.add(data[i]); } else { pq.add(data[i]); while(!pq.isEmpty()) { System.out.println(pq.peek().Index+" "+pq.peek().val); pq.remove(); } System.out.println(); } } return true; } } public class Main { public static void main(String[] args) { Solution space=new Solution(8); space.LongPath(); space.printPath(); space.pushQueue(); } }
标签:system void highlight ide path this ble for add
原文地址:https://www.cnblogs.com/z2529827226/p/11622359.html