随笔分类 -  LeetCode

上一页 1 ··· 8 9 10 11 12
摘要:快速排序法 import java.util.Arrays; public class Algorithm { public static void main(String[] args) { int[] arr = {1,3,5,7,2,4,6,8}; System.out.println(Arr 阅读全文
posted @ 2021-10-24 15:05 振袖秋枫问红叶 阅读(25) 评论(0) 推荐(0)
摘要:import java.util.Arrays; public class Algorithm { public static void main(String[] args) { int[] arr = {1,3,5,7,2,4,6,8}; System.out.println(Arrays.to 阅读全文
posted @ 2021-10-24 14:58 振袖秋枫问红叶 阅读(33) 评论(0) 推荐(0)
摘要:双指针法(双路快速排序法) class Solution { public int findKthLargest(int[] nums, int k) { /** * 第k大的元素等同于第length - k小的元素 */ int target = nums.length - k; return s 阅读全文
posted @ 2021-10-24 14:43 振袖秋枫问红叶 阅读(52) 评论(0) 推荐(0)
摘要:暴力解法 直接遍历记录三种数字的个数 优化1——双指针法(三路快速排序法) class Solution { public void sortColors(int[] nums) { /** * 双指针遍历,i为当前遍历元素,如果为0就放在左边,为2放在右边,为1就继续遍历 */ int left 阅读全文
posted @ 2021-10-23 16:57 振袖秋枫问红叶 阅读(62) 评论(0) 推荐(0)
摘要:剑指 Offer 51. 数组中的逆序对 递归解法(超内存) public class Algorithm { public static void main(String[] args) { int[] nums = {7,5,6,4}; System.out.println(new Soluti 阅读全文
posted @ 2021-10-21 10:26 振袖秋枫问红叶 阅读(30) 评论(0) 推荐(0)
摘要:迭代 class Solution { public ListNode deleteDuplicates(ListNode head) { ListNode dummyHead = new ListNode(-1); dummyHead.next = head; ListNode cur = hea 阅读全文
posted @ 2021-10-18 15:36 振袖秋枫问红叶 阅读(35) 评论(0) 推荐(0)
摘要:迭代 class Solution { public ListNode mergeTwoLists(ListNode list1, ListNode list2) { /** * 依次比较两个链表的节点,将较小的节点放入新的链表 */ ListNode dummyHead = new ListNod 阅读全文
posted @ 2021-10-18 15:17 振袖秋枫问红叶 阅读(41) 评论(0) 推荐(0)
摘要:迭代 public class Algorithm { public static void main(String[] args) { int[] arr = {1, 2, 6, 3, 4, 5, 6}; ListNode head = new ListNode(arr); System.out. 阅读全文
posted @ 2021-10-18 13:36 振袖秋枫问红叶 阅读(30) 评论(0) 推荐(0)
摘要:203. 移除链表元素 虚拟头节点迭代 public class Algorithm { public static void main(String[] args) { int[] arr = {1, 2, 6, 3, 4, 5, 6}; ListNode head = new ListNode( 阅读全文
posted @ 2021-10-16 17:55 振袖秋枫问红叶 阅读(36) 评论(0) 推荐(0)
摘要:public class Algorithm { public static void main(String[] args) { MyCircularQueue queue = new MyCircularQueue(5); for (int i = 0; i < 6; i++) { System 阅读全文
posted @ 2021-10-15 15:13 振袖秋枫问红叶 阅读(29) 评论(0) 推荐(0)
摘要:import java.util.ArrayList; import java.util.List; class Solution { public List<String> buildArray(int[] target, int n) { List<String> list = new Arra 阅读全文
posted @ 2021-10-15 14:25 振袖秋枫问红叶 阅读(31) 评论(0) 推荐(0)
摘要:辅助栈实现 import java.util.Stack; class CustomStack { Stack<Integer> stack; int maxSize; public CustomStack(int maxSize) { stack = new Stack(); this.maxSi 阅读全文
posted @ 2021-10-15 13:24 振袖秋枫问红叶 阅读(35) 评论(0) 推荐(0)
摘要:辅助栈 import java.util.Stack; class MinStack { Stack<Integer> stack; Stack<Integer> minStack; public MinStack() { stack = new Stack<>(); minStack = new 阅读全文
posted @ 2021-10-15 10:42 振袖秋枫问红叶 阅读(37) 评论(0) 推荐(0)
摘要:用两个栈实现队列 import java.util.Stack; public class Algorithm { public static void main(String[] args) { MyQueue myQueue = new MyQueue(); for (int i = 0; i 阅读全文
posted @ 2021-10-14 21:47 振袖秋枫问红叶 阅读(24) 评论(0) 推荐(0)
摘要:用两个队列实现栈 import java.util.LinkedList; import java.util.Queue; public class Algorithm { public static void main(String[] args) { MyStack myStack = new 阅读全文
posted @ 2021-10-14 19:36 振袖秋枫问红叶 阅读(21) 评论(0) 推荐(0)
摘要:栈 import java.util.Scanner; import java.util.Deque; public class Algorithm { public static void main(String[] args) { Scanner scanner = new Scanner(Sy 阅读全文
posted @ 2021-10-14 19:32 振袖秋枫问红叶 阅读(32) 评论(0) 推荐(0)

上一页 1 ··· 8 9 10 11 12