diff --git "a/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/README.md" index cd621a58bc4e0..879547e84fa60 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/README.md" @@ -101,6 +101,30 @@ class Solution { } ``` +### **JavaScript** + +```js +/** + * Definition for singly-linked list. + * function ListNode(val) { + * this.val = val; + * this.next = null; + * } + */ +/** + * @param {ListNode} head + * @return {number[]} + */ +var reversePrint = function(head) { + let res = []; + while (head != null) { + res.unshift(head.val); + head = head.next; + } + return res; +}; +``` + ### **Go** ```go @@ -179,6 +203,31 @@ public: }; ``` +### **TypeScript** + +```ts +/** + * Definition for singly-linked list. + * class ListNode { + * val: number + * next: ListNode | null + * constructor(val?: number, next?: ListNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.next = (next===undefined ? null : next) + * } + * } + */ + + function reversePrint(head: ListNode | null): number[] { + let res: number[] = []; + while (head != null) { + res.unshift(head.val); + head = head.next; + } + return res; +}; +``` + ### **...** ``` diff --git "a/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.ts" "b/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.ts" new file mode 100644 index 0000000000000..263cc22fa6606 --- /dev/null +++ "b/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.ts" @@ -0,0 +1,20 @@ +/** + * Definition for singly-linked list. + * class ListNode { + * val: number + * next: ListNode | null + * constructor(val?: number, next?: ListNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.next = (next===undefined ? null : next) + * } + * } + */ + + function reversePrint(head: ListNode | null): number[] { + let res: number[] = []; + while (head != null) { + res.unshift(head.val); + head = head.next; + } + return res; +}; \ No newline at end of file