Leetcode 202 question: two solutions to Happy Number

Title Description Determines whether a number n is a happy number. The definition of happy number is as follows: Starting with any positive integer, replace the number by the sum of the squares of its digits. Repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those ...

Posted by redrabbit on Sat, 20 Nov 2021 21:35:38 -0800

Minimum spanning tree of graph (implementation and explanation of prim algorithm and kruskal algorithm)

catalogue   1. Topic introduction   Let's start with the topic  , It is convenient to understand and reflect the algorithm more intuitively 2. Introduce my understanding of the implementation of prim algorithm code in books 1. Function of lowcast array 2. Function of adjvex array 3.kruskal algorithm 3. If you want the sou ...

Posted by rpanning on Sat, 20 Nov 2021 21:24:35 -0800

199. Right view of binary tree

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} ...

Posted by sxiix on Sat, 20 Nov 2021 19:28:59 -0800

[CF335F]Buy One, Get One Free

Buy One, Get One Free Problem solution First of all, if it has no requirements and can only choose strictly less than as a gift, I think it should be easy for us to think of a greedy strategy of choosing one after the other. But obviously, under the strict requirements, we can't do so and consider going back on our greed. We can reduce gifts ...

Posted by horstuff on Sat, 20 Nov 2021 17:06:32 -0800

Programmer's interesting algorithm Q20: suffering facade magic square

1. Problem description          There is a famous scenic spot in Spain called the holy family hall. The "crucifixion Facade" mainly depicts the scene of Jesus from "the last supper" to "Ascension". There is also a magic cube array as shown in the figure below, which is famou ...

Posted by space1 on Sat, 20 Nov 2021 14:45:52 -0800

Detailed explanation of ac automata (multi-mode string matching with mismatch pointer)

ac automata is an algorithm used to calculate multiple string matches. As we know, K M P KMP KMP realizes the matching of single-mode strings in an ingenious way (using a single string to ask whether the string appears ...

Posted by Hopps on Sat, 20 Nov 2021 14:12:33 -0800

(Problem) "Algorithms Zero Base 100 Lecture" (Lecture 31) Multidimensional Enumeration - Introduction

1. Judgment Subsequence ( leetcode392) The idea is that we can use violence directly for pattern matching, but if we use violence directly in addition to the kmp algorithm, we do not need to use backtracking, because it is not a continuous substring, but a subsequence, as long as we find the s characters in t and the order is the same, we c ...

Posted by g.grillo on Sat, 20 Nov 2021 13:59:36 -0800

Generic template design from matrix fast power -- teach you how to elegant object-oriented

What is the fast power of a matrix? Fast power is a fast method to solve the power of a number by using binary. The principle of fast power will be briefly explained later. If you still don't understand it, please Baidu yourself. I believe that many young friends are new to college and may not have studied linear algebra (such as me), so ...

Posted by Merve on Sat, 20 Nov 2021 13:02:55 -0800

Principle and workflow analysis of rsync algorithm

This paper analyzes the principle of rsync algorithm and the workflow of rsync through examples, which is the explanation of rsync's official technical report and official recommended articles. This article will not describe how to use the rsync command, but explain in detail how it can achieve efficient incremental transmission. The following ...

Posted by sean04 on Sat, 20 Nov 2021 11:14:26 -0800

Summary of week 2021-11-19

A: A (codeforces.com) In the sign in question in Guilin a few days ago, I became a volunteer. A team showed me that it was stupid after a minute. Then I directly copied the classic. In a minute, it was two wins in three games and three wins in five games. Just output 2n-1 B: Problem - 940E - Codeforces Meaning: Give you an array and a num ...

Posted by mentorbassment on Sat, 20 Nov 2021 07:35:50 -0800