Build a min heap for a given a given array
来源:互联网 发布:超人软件站 编辑:程序博客网 时间:2024/05/29 04:40
public class Solution { public void heapify(int[] A) { // only heapify the parent nodes from 0 to A.length-1/2 // from bottom to up, call minHeapify() for (int i=(A.length-1)/2; i>=0; i--) { minHeapify(i, A); } } public void minHeapify(int i, int[] A) { while (2*i+1 < A.length) { // A[son] is the minimum of the two children int son = 2*i+1; if (2*i+2<A.length && A[son] > A[2*i+2]) { son = 2*i+2; } if (A[son] >= A[i]) { break; } // swap the minimum with parent int temp = A[son]; A[son] = A[i]; A[i] = temp; // check if son is a heap i = son; } }}
0 0
- Build a min heap for a given a given array
- 27. Given an array and a value
- If given a choice
- Reach a given score
- CareerCup Given an array having positive integers, find a subarray which adds to a given number
- Find the maximum subarray XOR in a given array
- reverse a given string StringTokenizer
- You're Given a String...
- You are given a tetrahedron.
- A. You're Given a String...
- A - You‘re Given a String
- A. You\'re Given a String...
- CareerCup Given a sorted array which contains scores. Write a program to find occurrence
- For example,Given input array A=[1,1,2], your fuction will return length=2,ans A is now {1,2}
- Cannot format given Object as a Date
- No. 09 - Numbers with a Given Sum
- Cannot format given Object as a Date
- Binary representation of a given number
- 在Windows下搭建RocketMQ
- Intellij_idea远程开启debug
- Unity NGUI对特效的显示范围进行控制
- 打开和保存文件对话框 调用动态库
- Unity打包安卓 Found plugins with same names x86_64
- Build a min heap for a given a given array
- 浅析Java注解
- 1029. 旧键盘(20)
- webview加载网页和assets的html文件
- 冒泡排序(Java)
- 文章标题
- Groovy代码优化-递归格式化参数
- 使用Ajax验证用户名是否存在
- 动画效果改变view的高度