Determine if the given integer array is min heap.
1 public class Solution { 2 public boolean isMinHeap(int[] array) { 3 // Write your solution here 4 if (array == null || array.length == 0) { 5 return true ; 6 } 7 int pre = array[0] ; 8 for (int i = 1; i<array.length; i++ ) { 9 if (pre > array[i]) { 10 return false ; 11 } 12 } 13 return true ; 14 } 15 }
原文地址:https://www.cnblogs.com/davidnyc/p/8685555.html
时间: 2024-11-10 08:19:15