public void heapify(int[] nums) {
        int n = nums.length - 1;
        for (int i = n / 2; i >= 0; --i) {
            int k = i;
            while (2 * k + 1 <= n) {
                int child = 2 * k + 1;
                if (child < n) {
                    // there's two children nodes
                    if (nums[child] > nums[child + 1]) {
                        child += 1;
                    }
                }
                if (nums[k] <= nums[child])
                    break;
                else {
                    swap(nums, k, child);
                    k = child;
                }
            }
        }
    }