var arr=[xxxxxxxxxxxxx]
var aa='你想要找的御祥脊数'镇渗
for(宴森x in arr)
{
if(x==aa)
{alert('有这个数')}
}
挺简单的啊。。 关键在于理解迟宽heapimport java.util.Arrays
public class Du {
public static void main(String[] args) {
int[] testAry1 = {1, 3, 5, 7, 9, 11}
System.out.println("{1, 3, 5, 7, 9, 11} is " + (isHeap(testAry1)? "": "NOT ") + "heap array.")
int[] testAry2 = {1, 3, 5, 7, 13, 9, 11}
System.out.println("枝隐{1, 3, 5, 7, 13, 9, 11} is "猛旦厅 + (isHeap(testAry2)? "":"NOT ") + "heap array.")
}
/**
* Will receive an integer heap array, method will return true or false
* depending on whether the array is believed to be a valid heap or not
*
* @param heap
*0-based integer array
* @return true if integer array is a heap, else false
*/
public static boolean isHeap(int[] heap) {
if(heap == null || heap.length == 0){
return false
}
int[] ary = new int[heap.length]
for(int i = 0i <heap.lengthi++){
ary[i] = heap[i]
}
Arrays.sort(ary)
for(int i = 0i <heap.lengthi++){
if(ary[i] != heap[i]){
return false
}
}
return true
}
}
---------------
{1, 3, 5, 7, 9, 11} is heap array
{1, 3, 5, 7, 13, 9, 11} is NOT heap array
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)