var inp = "{(A=>B),(B=>C),(C=>E)}";
var arr = inp.slice(1, inp.length - 1).split(",");
console.log(inp)
function TreeNode(val = null, next = null){
this.val = val;
this.next = next;
}
//deal with input
var set = new Set();
for (let i = 0; i < arr.length; i++){
set.add(arr[i][1]);
set.add(arr[i][4]);
}
var node = [...set];
var tr = [];
for(let x of node) {
tr.push(new TreeNode(x));
}
for (let i = 0; i < arr.length; i++){
var node1val = arr[i][1],
node2val = arr[i][4];
var node1, node2;
for(let x of tr){
if(x.val == node1val) node1 = x;
if(x.val == node2val) node2 = x;
}
node1.next = node2;
}
// 对比是否有链
var isHasCycle = function(head){
try{
JSON.stringify(head);
}catch(e){
return true;
}
return false;
}
var ans = isHasCycle(tr[0]);
console.log(ans)