Comments (4)
在链表长度为2的时候,会形成环形
先谢谢你,不然我也没发现
from duyi-webalgorithm.
在链表长度为2的时候,会形成环形 baby 我来帮你实现了
function Node(value) {
this.value = value
this.next = null
}
var a = new Node("a")
var b = new Node("b")
var c = new Node("c")
var d = new Node("d")
var e = new Node("e")
var f = new Node("f")
function bindNode(...arg) {
for (let i = 0; i < arg.length - 1; i++) {
var cur = arg[i]
cur.next = arg[i + 1]
}
}
bindNode(a, b, c, d, e, f)
function reverse(node) {
if (node === null || node.next === null) {
return node;
}
if (node.next.next === null) {
node.next.next = node
var last = node.next//返回最后一位
node.next = null//吧最后一位的上一位设置成空
return last
} else {
var result = reverse(node.next)//result 一直为最后一位
node.next.next = node// 这句话对应最后一次循环 吧倒数第二位的next的指向倒数三位
node.next = null// 这句话对应最后一次循环 吧 倒数第三为的next 指向null
return result
}
}
console.log(reverse(a));
from duyi-webalgorithm.
空链表也不对呀,课程开头也说了:“考算法题的时候,一分没有必须有严谨性判断”
from duyi-webalgorithm.
感谢提醒,bug已修复到对应分支,请重新拉取
from duyi-webalgorithm.
Related Issues (3)
- 广度优先搜索代码有问题
- 28-代码实现二叉树的广度优先搜索 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from duyi-webalgorithm.