斐波那契数列
2023/2/11小于 1 分钟
算法相关文档格式模版
题目链接
题目描述
刷题思路
代码实现
/**
* 链表结点
*/
export function ListNode(x) {
this.val = x
this.left = null
this.right = null
}
const root = {
val: 8,
left: {
val: 6,
left: { val: 5, left: null, right: null },
right: { val: 7, left: null, right: null },
},
right: {
val: 10,
left: { val: 9, left: null, right: null },
right: {
val: 11,
left: null,
right: {
val: 12,
left: null,
right: null,
},
},
},
}
console.log(root)
/**
* 注意,是返回结点
*/
export function KTheNode(pRoot, k) {
return inOrder(pRoot)[k - 1]
}
/**
* 中序遍历
*/
export function inOrder(root) {
if (root === null) {
return []
}
return inOrder(root.left).concat([root]).concat(inOrder(root.right))
}一些建议
更新日志
2024/7/29 23:43
查看所有更新日志
5a2b2-于c0f2d-于06596-于9b9e4-于b0275-于5f1e1-于02ab1-于8de1a-于ced18-于a23ce-于bc074-于80f08-于e34c0-于74aa9-于3c22c-于9bbe9-于e4c74-于
