更新 Solution.java
parent
bf2e20cde9
commit
22bc22261f
|
|
@ -81,28 +81,29 @@ public class Solution {
|
||||||
}
|
}
|
||||||
//合并数组冒泡排序实现
|
//合并数组冒泡排序实现
|
||||||
public static void merge(int[] nums1, int m, int[] nums2, int n) {
|
public static void merge(int[] nums1, int m, int[] nums2, int n) {
|
||||||
int[] nums= new int[m + n];
|
System.arraycopy(nums2, 0, nums1, m, n);
|
||||||
for (int i = 0; i < m + n; i++) {
|
|
||||||
if (i < m){
|
|
||||||
nums[i] = nums1[i];
|
|
||||||
} else {
|
|
||||||
nums[i] = nums2[i - m];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 冒泡排序
|
// 冒泡排序
|
||||||
for (int i = 0; i < nums.length; i++) {
|
for (int i = 0; i < nums1.length; i++) {
|
||||||
for (int j = 0; j < nums.length; j++) {
|
for (int j = 0; j < nums1.length; j++) {
|
||||||
if (i != j) {
|
if (i != j) {
|
||||||
if (nums[i] < nums[j]){
|
if (nums1[i] < nums1[j]){
|
||||||
int temp = nums[i];
|
int temp = nums1[i];
|
||||||
nums[i] = nums[j];
|
nums1[i] = nums1[j];
|
||||||
nums[j] = temp;
|
nums1[j] = temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nums1 = nums;
|
|
||||||
String result = Arrays.stream(nums1).mapToObj(String::valueOf).collect(Collectors.joining(",", "[", "]"));
|
String result = Arrays.stream(nums1).mapToObj(String::valueOf).collect(Collectors.joining(",", "[", "]"));
|
||||||
System.out.println(result);
|
System.out.println(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int removeElement(int[] nums, int val) {
|
||||||
|
for (int i = 0; i < nums.length; i++) {
|
||||||
|
if (val == nums[i]){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nums.length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue