留蓝

文章 评论 浏览 28

留蓝 2022-05-04 13:55:39

// 用递归。第一步 处理递归到底的条件 第二步 构建一个更小问题的解。 第三步 用更小问题的解构建出原问题的解
第一步 很明显
第二步 reverse这个函数的宏观语意就是题目的意思,输入一个整数 返回 这个整数的逆序字符串。 那么将原num % 10 后得到一个子整数即新的num reverse(num)就很明确的求出了原数字 除了 个位的逆序数
第三步 将个位数与 reverse(num) 加起来 构建原问题的解
const reverse = (num: number): string => {
if (num < 10) {
return num.toString()
}
const cur = (num % 10).toString()
num = Math.floor(num / 10)
return cur + reverse(num)
}

第 99 题:编程算法题

留蓝 2022-05-04 13:54:47

写了一个满足基本要求的简易版的 让不明白的同学能够更快看懂

class Dialog {
  constructor(top,left,width,height) {
    this.top = top
    this.left = left
    this.el = null
    this.w = width
    this.h = height
    this.originX = 0
    this.originY = 0
    this.mouseL = 0
    this.mouseT = 0
  }
  show(content) {
    this.el = document.createElement('div')
    document.body.appendChild(this.el)
    this.el.style = `
    width:${this.w}px;
    height:${this.h}px;
    position:absolute;
    top:${this.top}px;
    left:${this.left}px;
    border:1px solid #ccc;
    `
    this.el.innerHTML = content
    this.el.addEventListener('mousedown',function(e) {
      this.originX = e.pageX
      this.originY = e.pageY
      this.mouseL = this.originX - this.offsetLeft
      this.mouseT = this.originY - this.offsetTop
      function move(e) {
        this.style.left = (e.pageX - this.mouseL) + 'px'
        this.style.top = (e.pageY - this.mouseT) + 'px'
      }
      this.addEventListener('mousemove',move)
      this.addEventListener('mouseup',function(e) {
        this.removeEventListener('mousemove',move)
      })
    }) 
  }
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script src="./dialog类.js"></script>
  <script>
    new Dialog(100,100,500,500).show('helloworld')
  </script>
</body>
</html>

第 132 题:实现一个 Dialog 类,Dialog 可以创建 dialog 对话框,对话框支持可拖拽

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文