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

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

(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

Longest substring without repeated characters (C + + problem solution, including VS runnable source code)

1. Force buckle C + + source code class Solution { public: int lengthOfLongestSubstring(string s) { map<char, int> hash; int ans = 0; int i = 0; int n = s.length(); for (int j = 0; j < n; j++) { if (hash.find(s[j]) != hash.end()) { i = max(hash.find(s[j])-> ...

Posted by ShaolinF on Sat, 20 Nov 2021 13:24:24 -0800

[HBU-DS] 7-5 tribes (and search Collection)

7-5 tribes (20 points) subject In a community, everyone has his own small circle and may belong to many different circles of friends at the same time. We think that all friends of friends are in one tribe, so please count how many disjoint tribes there are in a given community? And check whether any two people belong to the same tribe. Input ...

Posted by delorian on Sat, 20 Nov 2021 11:29:49 -0800

Linux basic instructions

Command format command [options] [arguments] Basic instructions: Directory related instructions, ordinary file instructions, matching search instructions, permission related instructions Instruction usage rules: instruction name [operation option] [operation object] Instruction Name: the name of a command, indicating the command to be exe ...

Posted by mikie46 on Fri, 19 Nov 2021 21:39:48 -0800

557. (Reverse Words in a String III) reverses word III in a string

Title: Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. Given a string s, reverse the character order of each word in the sentence while still retaining the spaces and the original word order. Example 1: Input: s = "Let's take LeetCode contest" Output: ...

Posted by johnb352 on Fri, 19 Nov 2021 14:51:22 -0800

LeetCode notes_ 391. Perfect rectangle

Title Description Give you an array of rectangles, where rectangles[i] = [xi, yi, ai, bi] represents a rectangle with parallel coordinate axes. The lower left vertex of the rectangle is (xi, yi) and the upper right vertex is (ai, bi). Returns true if all rectangles together exactly cover a rectangular area; Otherwise, false is returned. ...

Posted by Baumusu on Fri, 19 Nov 2021 12:41:53 -0800

Summary of front-end routing knowledge points

1. The core of front-end Routing: Change the URL without overall refresh: Implementation methods: 1) hash of URL 2) history of html5 2. hash of URL location.hash=' ' 3. history of HTML5 history.pushState({}, ' ' , 'home' ) history.replaceState({},'','home') pushState() is like entering and exiting the stack. It is a stack structure that ca ...

Posted by ririe44 on Fri, 19 Nov 2021 06:16:50 -0800

LeetCode 524. Match the longest word in the dictionary by deleting letters (dynamic programming) / 695. Maximum area of islands / 54. Spiral matrix (back)

524. Match the longest word in the dictionary by deleting letters One question per day on September 14, 2021 Title Description Give you a string s and a string array dictionary as a dictionary, find and return the longest string in the dictionary, which can be obtained by deleting some characters in S. If there is more than one answer, the ...

Posted by Benjamin on Thu, 18 Nov 2021 22:26:22 -0800