@XQF
2018-03-07T22:53:57.000000Z
字数 395
阅读 716
数据结构与算法
邻居好好说话:
public class Solution {
public int[] bubbleSort(int[] nums) {
for (int i = 0; i < nums.length; i++) {
for (int j = 0; j < nums.length - i - 1; j++) {
if (nums[j] > nums[j + 1]) {
int temp = nums[j];
nums[j] = nums[j + 1];
nums[j + 1] = temp;
}
}
}
return nums;
}
public static void main(String[] args) {
Solution solution = new Solution();
int[] nums = {1, 2, 55, 6, 3, 2, 4, 5, 6, 8, 9, 0};
System.out.println(Arrays.toString(solution.bubbleSort(nums)));
}
}