• ## Leetcode No.167 two sum II – input array is sorted (c + + implementation)

Time：2021-12-21

1. Title 1.1 English title Given an array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Return the indices of the two numbers (1-indexed) as an integer array answer of size 2, where 1 <= answer[0] < answer[1] <= numbers.length. […]

• ## Algorithm | dichotomy

Time：2021-12-12

In data structure books, the precondition of order is often added when introducing dichotomy. The definition of order is either from large to small or from small to large. So, is order really a necessary condition for using dichotomy in solving all problems?The answer is: No As long as the elimination logic on the left […]

• ## Python’s case of finding the square root by dichotomy

Time：2021-10-15

I’ll stop talking nonsense. Let’s look at the code directly~ ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 def sq2(x,e):   e = E error range   low= 0   high = max(x,1.0）Treatment greater than0less than1Number of   guess = (low + high) / 2.0   ctr = 1      while […]

• ## Interview handwritten code list

Time：2021-3-9

Anti chattering function const debounce = (fn, wait) => { let _ = ” return (…arg) => { clearTimeout(_) _ = setTimeout(() => { fn.apply(this, arg) }, wait) } } input.addEventListener(“input”, debounce(ajax, 1000)); Throttling function const throttle = (fn, s) => { let a = +new Date(), _ return (…arg) => { let b = +new Date() – a if (b > s) { _ = setTimeout(() => { fn(arg); _ = ” }, s) a = +new Date() } } } input.addEventListener(“input”, throttle(ajax, 1000)); Deep copy (solve circular reference) function clone(target, map = new WeakMap()) { if (typeof target === ‘object’) { let cloneTarget = Array.isArray(target) ? [] : […]

• ## Display component and container component (by Dan Abramov, developer of Redux)

Time：2021-3-6

This article is translated fromPresentational and Container ComponentsThe author of the article isDan Abramov, he is also the author of Redux and create react app.In the actual development process of using react + Redux technology stack, a very good understanding of the concept of container component and display component is the basis of developing an […]

• ## [dichotomy algorithm] PHP implementation of binary search algorithm

Time：2020-10-28

\$a = array(1,2,33,24,15,16,7,8); function find2(\$a,\$findValue){ /** * [url= home.php?mod=space&uid=170990 ]@Name [/ url] dichotomy search algorithm * [url= home.php?mod=space&uid=686208 ]@Author [/ url] * [url= home.php?mod=space&uid=952169 ]@Param [/ url] \$a: array passed, \$findvlaue: value to find * [url= home.php?mod=space&uid=155549 ]@Return [/ url] true found, false not found */ sort(\$a); \$heigh = count((array)\$a)-1; \$low = 0; while (\$heigh>=\$low) […]

• ## Leetcode 35 search insertion location

Time：2020-10-15

Leedcode35 search insertion location The main idea of solving the problem is that the target array is ordered array, and the efficiency of searching by dichotomy is higher //Title: //Given a sort array and a target value, find the target value in the array, And returns its index. If the target value does not exist […]

• ## The longest common prefix

Time：2020-8-18

Address: https://leetcode-cn.com/probl… Title Description Analysis topic The most intuitive feeling about this problem is: First string foundtarget Perform a horizontal scan by column My code is as follows: /** * @param {string[]} strs * @return {string} */ var longestCommonPrefix = function(strs) { if (!strs || !strs.length) { return ” } let target = strs[0] for […]

• ## Binary search (C language)

Time：2020-4-10

Dichotomy is an efficient search method, which is suitable forIt’s in orderArray Basic thinking Search and judge from the middle number of the array. If it is not the number to be searched, compare the size. Then search and judge from the middle on one side of the two sides separated from the middle, and […]

• ## How to find out whether an ordered array contains a value in PHP (binary search)

Time：2020-4-6

Problem: for an ordered array, how to judge whether a given value exists in the array.   Idea: the simplest way to judge whether there is an array is to directly loop the array and compare each value. But for an ordered array, this writing does not make good use of the “ordered” feature. So […]