留蓝 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>
- 共 1 页
- 1
// 用递归。第一步 处理递归到底的条件 第二步 构建一个更小问题的解。 第三步 用更小问题的解构建出原问题的解
第一步 很明显
第二步 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 题:编程算法题