Sword finger Offer 62 The last remaining number in the circle (java implementation) -- three solutions (violence, linked list, Mathematics) LeetCode -- Joseph Ring problem

Title: The N numbers 0,1, ····, n-1 are arranged in a circle, starting from the number 0, and the m-th number is deleted from the circle each time (counting from the next number after deletion). Find the last number left in the circle. For example, the five numbers 0, 1, 2, 3 and 4 form a circle. Starting from ...

Added by guyfromfl on Wed, 02 Mar 2022 17:33:18 +0200

Binary tree - pre order, middle order, post order, sequence (recursive & non recursive)

Binary tree - preorder traversal (middle left right) recursion # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def preorderTraversal(self, root: TreeNode) -> List[int]: ...

Added by CUatTHEFINISH on Wed, 02 Mar 2022 15:08:01 +0200

Sword finger Offer 64 Find 1 + 2 +... + n

Sword finger Offer 64 Find 1 + 2 +... + n 1. Title Description For 1 + 2 +... + n, it is required that keywords such as multiplication and division, for, while, if, else, switch, case and conditional judgment statements (A?B:C) cannot be used. Example 1: Input: n = 3 Output: 6 Example 2: Input: n = 9 Output: 45 Restrictions: ...

Added by justintoo1 on Wed, 02 Mar 2022 01:36:09 +0200

leetcode363 - the maximum value of the rectangular area does not exceed the sum of K (prefix and + dichotomy) (TreeSet or auxiliary array dynamic return)

introduce My LeetCode homepage, one problem one solution Tags: queue, dynamic programming, binary search 363. The rectangular area does not exceed the maximum value of K and Difficulty difficulty 363. The rectangular area does not exceed the maximum value of K and: https://leetcode-cn.com/problems/max-sum-of-rectangle-no-larger-than-k ...

Added by Piba on Wed, 02 Mar 2022 01:12:42 +0200

Binary tree arrangement 2

1. Find the minimum depth of binary tree First, understand the concept of minimum depth: minimum depth is the number of nodes on the shortest path from the root node to the nearest leaf node., Note the leaf node. If so, the branch without left child will be regarded as the shortest depth. Therefore, if the left subtree is empty and the right s ...

Added by realjumper on Tue, 01 Mar 2022 16:16:14 +0200

Leetcode6: zigzag transformation (medium, displacement processing)

catalogue 1. Title Description 2. Problem solving analysis 2.1 solution 1: two dimensional matrix simulation 2.2 solution 2: directly calculate the address 3. Code implementation 1. Title Description A given string s is arranged in a Z-shape from top to bottom and from left to right according to the given number of lines numRows. For ...

Added by priya_cks on Tue, 01 Mar 2022 02:45:11 +0200

Notes: summary of common data structure knowledge points in Java

1. Data structure classification Java data structures can be divided into two categories according to linearity and nonlinearity: ① Linear data structure: array, linked list, stack, queue ② Nonlinear data structure: tree, heap, hash table, graph 2. Linear data structure 2.1 array Array is a data structure that stores elements in continuous ...

Added by Rose.S on Mon, 28 Feb 2022 15:25:59 +0200

LeetCode brush notes binary tree path sum

112 path sum Given a binary tree root and a value sum, judge whether there is a path where the sum of node values from the root node to the leaf node is equal to sum. Enter a binary tree and a given integer, and output a Boolean value to indicate whether there are paths that meet the conditions. Input: root = [5,4,8,11, null, 13,4,7,2, nu ...

Added by kat89 on Mon, 28 Feb 2022 14:18:07 +0200

Algorithm / sliding window

Sliding windows are divided into two types: unfixed window size and fixed window size: (commonly used when looking for substrings that meet certain requirements) 1) Unfixed window size: the window size will change. When the current window does not meet the requirements, it will move backward as a whole. 2) Fixed window size: the window size i ...

Added by gavin1996 on Mon, 28 Feb 2022 09:30:33 +0200

New solution of sequence query

New solution of sequence query Topic background The previous question "sequence query" said: A=[A0,A1,A2 ···, An] is a sequence composed of n+1 integers in the range of [0,N], which satisfies 0 = A0 < A1 < A2 < ·· < An < n. Based on sequence a, for any integer x within the range ...

Added by Eggzorcist on Mon, 28 Feb 2022 09:05:33 +0200