乐闻世界
Explore
AI Space
Tags
Articles
Tutorials
Interview Prep
Q&A
Resources
Tools
算法
乐闻
阅读 5714
2022年6月18日 12:24
分治思想在排序算法中的应用 - 快速排序&归并排序
前言排序算法在编程中是最简单最基础的算法,同时快速排序和归并排序都是通过递归调用的方式进行排序的,对于递归而言,比较不好理解。记录一下快速排序和归并排序的Javascript代码实现以及两种算法的相同点与差异性。快速排序functionquickSort(arr){if(arr.length=1){returnarr;}constmid=Math.floor(arr.length/2);const
JavaScript
算法
算法
乐闻
阅读 2611
2022年6月18日 11:42
从上到下按层打印二叉树
从上到下按层打印二叉树问题解决方案BFS广度遍历/***Definitionforabinarytreenode.*functionTreeNode(val){*this.val=val;*this.left=this.right=null;*}*//***@param{TreeNode}root*@return{number[][]}*/varlevelOrder=function(root){
数据结构
算法
乐闻
阅读 2394
2022年6月12日 21:49
「数据结构」树的遍历
functiondfs(root){//dosthdfs(root.left);dfs(root.right);}functiondfs(root){dfs(root.left);//dosthdfs(root.right);}functiondfs(root){dfs(root.left);dfs(root.right);//dosth}...
数据结构