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
Side length of the island (DFS / iteration)
There are many ideas for this question. Because I have recently studied DFS, my first idea is DFS
The following is the code I wrote (very lengthy (not very good idea))
My first thought: when I encounter 1, I will enter the depth search of the island. I will traverse every piece of land up, down, left and right. If there is cross-border or w ...
Added by Synergic on Wed, 02 Mar 2022 06:57:22 +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
Basic algorithm - backtracking method (maze problem)
Author: Steven Copyright notice: the copyright belongs to the author. For commercial reprint, please contact the author for authorization. For non-commercial reprint, please indicate the source
preface
This paper introduces a classical algorithm backtracking method, which can be used as a solution to the maze problem. The following is ...
Added by richie19rich77 on Wed, 02 Mar 2022 00:56:05 +0200
Introduction to LintCode python
Add: omit some questions. Here I think the questions that need to be posted are posted by me. The answers are different. You are welcome to express your views. I'll start with a brick to attract jade. Of course, the questions here are incomplete, and they will be supplemented in the follow-up.
2940. Byte string and string conversion
descri ...
Added by LeslieHart on Tue, 01 Mar 2022 18:14:43 +0200
Algorithm: tree structure
tree
Definition and related concepts of tree
Start with the linked list and diagram
Linked list
In the previous content, we learned the basic data structure of linked list. Single linked list is one of them. The structure form is as follows:
# Definition for the singly-linked list.
Class ListNod:
def __init__(self, val=0, next=Non ...
Added by iHack on Tue, 01 Mar 2022 16:07:37 +0200
[layering diagram shortest circuit] [shortest circuit deformation] communication line AcWing340
There are N communication base stations in the suburbs, P two-way cables, and the i cable connects the base stations Ai and Bi.
In particular, base station 1 is the main station of the communication company, and base station N is located in a farm.
Now, the farmer wants to upgrade the communication line, and upgrading the i Cable Costs Li.
T ...
Added by Chief on Tue, 01 Mar 2022 14:26:31 +0200
Maximum value of sequence interval - RMQ / line segment tree / tree array
subject
Enter a string of numbers and give you M inquiries. Each inquiry will give you two numbers x and Y, asking you to say the maximum number in the range from X to Y.
Input format In the first line, there are two integers n, and M represents the number of numbers and the number of times to ask;
The number of next row N;
Next M lines, ea ...
Added by freakus_maximus on Tue, 01 Mar 2022 13:52:14 +0200
Interviewer: jdk1 8 How is the HashMap capacity expansion rehash algorithm optimized?
This article talks about a common interview question, jdk1 8 How is the HashMap capacity expansion rehash algorithm optimized?
As we all know, the bottom layer of HashMap is actually an array. Since it is an array, the inevitable length is fixed, so there must be a problem of capacity expansion. At jd.k1 7 is to double the capacity of the arra ...
Added by az_wraith on Tue, 01 Mar 2022 07:11:59 +0200