当我尝试修改import java.util.Arrays;
public class Solution {
public static void main(String[] args) {
int[] array = {3,5,1,2,4,8};
int[] result = mergeSort(array);
System.out.println(Arrays.toString(result));
}
public static int[] mergeSort(int[] array) {
if (array == null || array.length <= 1) {
return array;
}
int[] helper = new int[array.length];
sort(array, helper, 0, array.length - 1);
return array;
}
public static void sort(int[] array, int[] helper, int left, int right) {
if (left >= right) {
return;
}
int mid = (left - right)/2 + right;
//int mid = left + (right - left) / 2;
sort(array, helper, left, mid);
sort(array, helper, mid + 1, right);
combine(array, helper, left, mid, right);
}
public static void combine(int[] array, int[] helper, int left, int mid, int right) {
for (int i = left; i <= right; i++) {
helper[i] = array[i];
}
int leftIndex = left;
int rightIndex = mid + 1;
while (leftIndex <= mid && rightIndex <= right) {
if (helper[leftIndex] <= helper[rightIndex]) {
array[left] = helper[leftIndex];
left++;
leftIndex++;
} else {
array[left] = helper[rightIndex];
left++;
rightIndex++;
}
}
while (leftIndex <= mid) {
array[left] = helper[leftIndex];
left++;
leftIndex++;
}
}
}
以添加FastClick事件注册时(见下文),它抱怨pages/_document.js
。我猜是因为它是在服务器上执行的,而ReferenceError: document is not defined
没有在服务器上定义。有什么办法解决吗?
document
答案 0 :(得分:1)
您可以使用<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Shadow Appear"/>
</LinearLayout>
</RelativeLayout>
来确保仅在前端执行代码。
process.browser
答案 1 :(得分:1)
pages/_document.js
仅根据next.js
documentation在服务器上呈现。
我建议在pages/_app.js
中使用该代码,该代码将在所有组件之间共享。