xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Typescript & LinkedList All In One

Typescript & LinkedList All In One


"use strict";

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 * @created 2022-02-09
 * @modified
 *
 * @description Typescript & LinkedList All In One
 * @augments
 * @example
 * @link
 *
 */

const log = console.log;

function ListNode(this: any, val: any, next: any = undefined) {
  // constructor() {}
  this.val = (val === undefined ? 0 : val)
  this.next = (next === undefined ? null : next)
}

// function ListNode(val: any, next: any = undefined) {
//   // constructor() {}
//   this.val = (val === undefined ? 0 : val)
//   this.next = (next === undefined ? null : next)
// }
// 'this' implicitly has type 'any' because it does not have a type annotation.ts(2683)

let arr = [2, 4, 3];

let root = new (ListNode as any)(arr.pop());
// let root = new ListNode(arr.pop());
let head = root;
log('head ', head);
while (arr.length) {
  if (!head.next) {
    const value = arr.pop();
    head.next = new (ListNode as any)(value);
    // head.next = new ListNode(value);
    log('head.next ', head.next);
    head = head.next;
  }
}
// 'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.ts(7009)
log('root ', root);

export {};


https://stackoverflow.com/questions/43623461/new-expression-whose-target-lacks-a-construct-signature-in-typescript

refs

https://leetcode.com/problems/add-two-numbers/

https://www.cnblogs.com/xgqfrms/p/15873147.html#5011112



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2022-02-09 00:30  xgqfrms  阅读(30)  评论(2编辑  收藏  举报