This commit is contained in:
Zerroi 2024-03-03 20:08:28 +08:00
parent 0d06fed819
commit af3f2544bf
5 changed files with 110 additions and 1 deletions

View File

@ -4,7 +4,7 @@ public class First {
}
class Solution {
class SolutionFirst {
public String intToRoman(int num) {
String[] a1 = new String[] { "I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M" };
int[] a2 = new int[]{1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000};

View File

@ -0,0 +1,16 @@
package com.zerroi.leetcode.ThreeThree;
import java.util.ArrayList;
import java.util.List;
public class Second {
}
class SolutionSecond {
public List<String> generateParenthesis(int n) {
List<String> res = new ArrayList<>();
return res;
}
}

View File

@ -0,0 +1,28 @@
package com.zerroi.leetcode.sort;
public class BubbleSort {
public static void main(String[] args) {
Bubble bubble = new Bubble();
int[] res = bubble.bubble(new int[]{2, 1, 9, 3, 10});
for (int item : res) {
System.out.println("item = " + item);
}
}
}
class Bubble {
public int[] bubble(int[] nums) {
for (int i = 0; i < nums.length - 1; i++) {
for (int j = 0; j < nums.length - i - 1; j++) {
int temp;
if (nums[j] > nums[j + 1]) {
temp = nums[j];
nums[j] = nums[j + 1];
nums[j + 1] = temp;
}
}
}
return nums;
}
}

View File

@ -0,0 +1,30 @@
package com.zerroi.leetcode.sort;
public class InsertionSort {
public static void main(String[] args) {
Insertion insertion = new Insertion();
int[] ints = insertion.insertionSort(new int[]{2, 1, 9, 3, 10});
for (int item : ints) {
System.out.println("item = " + item);
}
}
}
class Insertion {
public int[] insertionSort(int[] nums) {
for (int i = 1; i < nums.length; i++) {
int temp = nums[i];
int j = i;
while (j > 0 && temp < nums[j - 1]) {
nums[j] = nums[j - 1];
j--;
}
if (j != i) {
nums[j] = temp;
}
}
return nums;
}
}

View File

@ -0,0 +1,35 @@
package com.zerroi.leetcode.sort;
/**
* 选择排序是一种简单直观的排序算法无论什么数据进去都是 O(n²) 的时间复杂度所以用到它的时候数据规模越小越好
* 唯一的好处可能就是不占用额外的内存空间了吧
* 1. 算法步骤
* 首先在未排序序列中找到最小元素存放到排序序列的起始位置
* 再从剩余未排序元素中继续寻找最小元素然后放到已排序序列的末尾
* 重复第二步直到所有元素均排序完毕
*/
public class SelectionSort {
public static void main(String[] args) {
Selection selection = new Selection();
int[] res = selection.selection(new int[]{2, 1, 9, 3, 10});
for (int re : res) {
System.out.println(re);
}
}
}
class Selection {
public int[] selection(int[] nums) {
for (int i = 0; i < nums.length; i++) {
for (int j = i + 1; j < nums.length; j++) {
int temp = 0;
if (nums[i] > nums[j]) {
temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}
}
return nums;
}
}