代码改变世界

随笔分类 -  算法

BM2 链表内指定区间反转

2022-09-21 13:28 by jetwill, 28 阅读, 收藏, 编辑
摘要: /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { 阅读全文

NowCoder BM1 反转链表

2022-08-31 13:18 by jetwill, 22 阅读, 收藏, 编辑
摘要: 描述 给定一个单链表的头结点pHead(该头节点是有值的,比如在下图,它的val是1),长度为n,反转该链表后,返回新链表的表头。 NowCoder BM1 反转链表 import java.util.*; /* public class ListNode { int val; ListNode n 阅读全文

QuickSort

2022-06-27 21:17 by jetwill, 100 阅读, 收藏, 编辑
摘要: Like Merge Sort, QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot. The 阅读全文

leetcode 226 Invert Binary Tree

2022-06-14 13:20 by jetwill, 18 阅读, 收藏, 编辑
摘要: Given the root of a binary tree, invert the tree, and return its root. Example 1: Input: root = [4,2,7,1,3,6,9] Output: [4,7,2,9,6,3,1] Example 2: Inp 阅读全文

leetcode 110 Balanced Binary Tree

2022-06-14 13:01 by jetwill, 15 阅读, 收藏, 编辑
摘要: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in which the lef 阅读全文

leetcode 104 maximum-depth-of-binary-tree

2022-06-14 12:38 by jetwill, 16 阅读, 收藏, 编辑
摘要: https://leetcode.cn/problems/maximum-depth-of-binary-tree/submissions/ https://www.bilibili.com/video/BV11Y4y1q7YA?p=27 Given the root of a binary tre 阅读全文

leetcode-0101 symmetric-tree

2022-05-31 21:14 by jetwill, 16 阅读, 收藏, 编辑
摘要: https://leetcode.cn/problems/symmetric-tree/ Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its cente 阅读全文

leetcode-0145 二叉树的后序遍历

2022-05-26 21:37 by jetwill, 12 阅读, 收藏, 编辑
摘要: https://leetcode.cn/problems/binary-tree-postorder-traversal/ /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode 阅读全文

leetcode-0144 二叉树的前序遍历

2022-05-26 21:12 by jetwill, 15 阅读, 收藏, 编辑
摘要: https://leetcode.cn/problems/binary-tree-preorder-traversal/submissions/ /** * Definition for a binary tree node. * public class TreeNode { * int val; 阅读全文

leetcode-0094 二叉树的中序遍历

2022-05-26 20:52 by jetwill, 12 阅读, 收藏, 编辑
摘要: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { 阅读全文

implement-queue-using-stacks

2022-05-18 21:32 by jetwill, 19 阅读, 收藏, 编辑
摘要: Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, pee 阅读全文

求解剑指Offer22 - 链表中倒数第K个节点

2022-05-18 21:01 by jetwill, 9 阅读, 收藏, 编辑
摘要: ListNode 的定义 package com.company; public class ListNode { int val; ListNode next; ListNode() {} ListNode(int val) { this.val = val; } ListNode(int val 阅读全文

leetcode-0876 Middle Of The Linked List

2022-05-17 08:53 by jetwill, 5 阅读, 收藏, 编辑
摘要: Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node. Examp 阅读全文

leetcode-0234 Palindrome Linked List

2022-05-16 21:49 by jetwill, 11 阅读, 收藏, 编辑
摘要: Given the head of a singly linked list, return true if it is a palindrome. Example 1: Input: head = [1,2,2,1] Output: true Example 2: Input: head = [1 阅读全文

leetcode-0206 reverse-linked-list

2022-05-16 21:25 by jetwill, 14 阅读, 收藏, 编辑
摘要: Given the head of a singly linked list, reverse the list, and return the reversed list. Example 1: Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Examp 阅读全文

leetcoce-160 相交链表

2022-05-16 20:49 by jetwill, 13 阅读, 收藏, 编辑
摘要: Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersec 阅读全文

leetcode-0142 linked-list-cycle-ii

2022-05-09 21:35 by jetwill, 11 阅读, 收藏, 编辑
摘要: Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null. There is a cycle in a linked list if there 阅读全文

leetcode-0083 remove duplicates from sorted list

2022-05-09 21:20 by jetwill, 8 阅读, 收藏, 编辑
摘要: Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well. Example 阅读全文

leetcode-0141 linked-list-cycle

2022-05-09 21:17 by jetwill, 18 阅读, 收藏, 编辑
摘要: Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the 阅读全文

leetcode-0021 merge-two-sorted-lists

2022-05-07 09:02 by jetwill, 28 阅读, 收藏, 编辑
摘要: You are given the heads of two sorted linked lists list1 and list2. Merge the two lists in a one sorted list. The list should be made by splicing toge 阅读全文