447. Number of boomerangs

For n points equidistant from m, we get n*(n-1) boomerangs. Use hash charts to store key distances and value occurrences.

var numberOfBoomerangs = function(points) {
    let sum = 0
    for (let point1 of points) {
        const crl = new Map(a)for (let point2 of points) {
            const dis = 
            Math.sqrt((point1[1]-point2[1]) * *2 + (point1[0]-point2[0]) * *2)
            if(point1 ! = point2) crl.set(dis, (crl.get(dis) ||0) + 1)}for (const v of crl.values()) {
        sum += v * (v - 1)}}return sum
};
Copy the code

70. Climb the stairs

var climbStairs = function(n) {
    if (n == 1 || n == 2) return n
    let p = 1, q = 2, res
    for (let i = 3; i <= n; i++) {
        res = p + q
        p = q
        q = res
    }
    return res
};
Copy the code