LeetCode brush notes binary tree binary search tree operation
669 pruning binary search tree
Given a binary lookup tree and two integers L and R, and l < R, try pruning the binary lookup tree so that the values of all nodes after pruning are within the range of [L, R].
The input is a binary lookup tree and two integers L and R, and the output is a trimmed binary lookup tree.
Input: root = [3,0,4, ...
Added by kindoman on Mon, 22 Nov 2021 07:29:33 +0200
leetcode valid parentheses and circular queues
1. Valid brackets
This topic comes from leetcode valid parentheses
1.1 Title Description
Tips
1.1.1 interface function
bool isValid(char * s){
}
1.2 general framework
Although the array can also solve the problem, it is not very good. Some problems will appear later. We try to use the stack to solve the problem
Directly using ...
Added by N350CA on Mon, 22 Nov 2021 04:28:16 +0200
[LeetCode binary tree project] verify binary search tree (98)
1. Title
Give you the root node of a binary tree, root, to determine whether it is an effective binary search tree.
A valid binary search tree is defined as follows:
The left subtree of the node only contains the number less than the current node;The right subtree of a node contains only the number greater than the current node;All l ...
Added by spyke01 on Sat, 20 Nov 2021 10:20:44 +0200
Knapsack type problem
Article catalog
preface
Follow labuladong to brush the questions and make some notes. The original website link is: link.
1. Classical dynamic programming: 0-1 knapsack problem
Give you a backpack with a weight of W and N items. Each item has two attributes: weight and value. The weight of the ith item is wt[i] and the value is val[i]. ...
Added by Kower on Thu, 18 Nov 2021 04:32:33 +0200
Force deduction operation
x ^ 0s = x x ^ x = 0 N & (n - 1) the lowest bit in the bit level representation of N can be removed. For example, for the binary representation 11110100, subtract 1 to obtain 11110011, and the two numbers are bitwise combined to obtain 11110000. N & (- n) can get the lowest bit in the bit level representation of N. for example, for the ...
Added by doug007 on Wed, 17 Nov 2021 17:28:48 +0200
Leetcode sword finger Offer 03 - 10 Java problem solution
Sword finger Offer 03. Duplicate number in array
Violent cycle, timeout TAT
class Solution {
public int findRepeatNumber(int[] nums) {
for (int i = 0; i < nums.length; i++) {
for (int j = 0; j < nums.length; j++) {
if (i != j && nums[i] == nums[j]) {
return nums[i];
...
Added by Gafaddict on Tue, 16 Nov 2021 12:58:26 +0200
leetcode [stack and queue-difficulty] 239. sliding window
Preface
Hello, I'm a long way from junior year to junior year. The direction is back-end and occasionally front-end. Now the main language is Java. Before a long time, I was learning some technology of web development, but I haven't done anything like data structure, algorithm and so on for a long time. I intend to pick it up and do a good ...
Added by ben.hornshaw on Fri, 12 Nov 2021 21:05:02 +0200
leetcode 347. First K high frequency elements
Preface
Hello, I'm a long way from junior year to junior year. The direction is back-end and occasionally front-end. Now the main language is Java. Before a long time, I was learning some technology of web development, but I haven't done anything like data structure, algorithm and so on for a long time. I intend to pick it up and do a good ...
Added by needphphelp on Fri, 12 Nov 2021 20:19:17 +0200
leetcode 101. symmetric binary tree
Preface
Hello, I'm a long way from junior year to junior year. The direction is back-end and occasionally front-end. Now the main language is Java. Before a long time, I was learning some technology of web development, but I haven't done anything like data structure, algorithm and so on for a long time. I intend to pick it up and do a good ...
Added by TechXpert on Fri, 12 Nov 2021 18:44:32 +0200
142. Ring linked list II
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *detectCycle(ListNode *head) {
ListNode* temp = head;
while(temp != nullptr && temp->val <100001){
temp-> ...
Added by elfynmcb on Fri, 12 Nov 2021 16:30:42 +0200