算法题

  • 链接:https://leetcode-cn.com/problems/number-of-boomerangs/
  • 解答 ```javascript var numberOfBoomerangs = function(points) { let ans = 0; for (const p of points) {
    1. const cnt = new Map();
    2. for (const q of points) {
    3. const dis = (p[0] - q[0]) * (p[0] - q[0]) + (p[1] - q[1]) * (p[1] - q[1]);
    4. cnt.set(dis, (cnt.get(dis) || 0) + 1);
    5. }
    6. for (const [_, m] of cnt.entries()) {
    7. ans += m * (m - 1);
    8. }
    } return ans; };
  1. <a name="FXU0i"></a>
  2. ### 手写题:
  3. - 链接:[https://bigfrontend.dev/zh/typescript/Trim](https://bigfrontend.dev/zh/typescript/Trim)
  4. - 答案
  5. ```javascript
  6. type Trim<T extends string> =
  7. T extends ` ${infer Left}` ? Trim<Left> :
  8. (T extends `${infer Right} ` ? Trim<Right> :
  9. T);