npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@masx200/leetcode-class

v1.2.7

Published

JavaScript Tools For LeetCode

Downloads

71

Readme

LeetCode-Class

This project is convenient for you to debug LeetCode

includes ListNode, TreeNode, Interval, Employee

ListNode

Constructor

const node = new ListNode(val);

Initialize using an array

(Follow LeetCode topic specifications): ListNode.create(arr : Array) : ListNode

const head = ListNode.create([1, 2, 3, 4, 5]);

Visual display

ListNode.prototype.visualShow() : void

const head = ListNode.create([1, 2, 3, 4, 5]);

head.visualShow();
//1 -> 2 -> 3 -> 4 -> 5

Initialize Cross linked List using arrays

(Follow LeetCode topic specifications, Example Question 160): ListNode.createIntersectList(firstArr: Array<any>,secondArr: Array<any>IntersectArr: Array<any>) : [ListNode, ListNode], parameters are: first ListArray Uncrossed, second ListArray Uncrossed, crossed

const [head1, head2] = ListNode.createIntersectList([1, 2], [3, 4], [5, 6]);

Transform ListNodes to array

ListNode.prototype.show() : Array

const head = ListNode.create([1, 2, 3]);

head.show();
// [1,2,3]
ListNode.show(head);
// [1,2,3]

Get the last ListNode for a ListNode

ListNode.prototype.getLast() : ListNode

const head = ListNode.create([1, 2, 3]);

head.getLast().show();
// [3]

Mock a ListNode with length n

ListNode.mock(n : Number) : ListNode

const head = ListNode.mock(5);

Interval

Constructor

Interval

const interval = new Interval(1, 3);

Initialize using an array

(Follow LeetCode topic specifications): Interval.createList(arr : Array[]) : Interval[]

const intervals = Interval.createList([
    [1, 2],
    [3, 4],
]);

Transform Interval to array

Interval.show() : Array

const interval = new Interval(1, 3);

interval.show();
// [1,3]
Interval.show(interval);
// [1,3]

Transform Intervals to arrays: Interval.showList() : Array[]

const intervals = Interval.createList([
    [1, 2],
    [3, 4],
]);

Interval.showList(intervals);
// [[1,2],[3,4]]

Employee

Constructor

Employee

const employee = new Employee(1);

(Follow LeetCode topic specifications): Employee.createArr(arr: [number, number, number[]][]) : Employee[]

TreeNode

Constructor

TreeNode

const node = new TreeNode(5);

Initialize using an array

(Follow LeetCode topic specifications): TreeNode.create(arr : Array) : TreeNode

P.S. LeetCode title specification is From top to bottom, from left to right, indispensable position fill withnull

const head = TreeNode.create([1, 2, 3, null, 4, null, null, 5, 6]);

Transfrom TreeNode to array

TreeNode.prototype.show() : Array

const head = TreeNode.create([1, 2, 3, null, 4, null, null, 5, 6]);

head.show();
// [1,2,3,null,4,null,null,5,6]
TreeNode.show(head);
// [1,2,3,null,4,null,null,5,6]

Visual display

TreeNode.prototype.visualShow() : void

const head = TreeNode.create([1, 2, 3, null, 4, null, null, 5, 6]);

head.visualShow();
// 1 -> 2
//        ↘→ 4 -> 5
//             ↘→ 6
//   ↘→ 3

Heap

Constructor

Heap

const heap = new Heap([2, 1, 0, 3, 4], null, false);

The first argument is inital array The second argument is how to get number from the element, default is null(get the value) For example:

const heap = new Heap(
    [
        { val: 2, name: "b" },
        { val: 1, name: "a" },
    ],
    (element) => element.val,
    false
);

The third parameter indicates whether it is the maximum heap, default is minimum heap

add element

Heap.prototype.add(element: T): number

heap.add(5);

delete element

Heap.prototype.delete() : T

head.delete();

get the minimum/maximum element

Heap.prototype.value[0]

head.value[0];

RunScript(For Constructor)

For Question 1172, Dinner Plate Stacks. issue is need For this is Test

Run

Execute input parameters in a certain order function runScript(ommonds: String[], inputs: any[][], classes?: any[]): any[]

// The parameters from left to right are
// commonds : List of executed commands
// inputs : Corresponding execution parameters
// classes : Corresponding execution class array
runScript(
    [
        "DinnerPlates",
        "push",
        "push",
        "push",
        "push",
        "push",
        "popAtStack",
        "push",
        "push",
        "popAtStack",
        "popAtStack",
        "pop",
        "pop",
        "pop",
        "pop",
        "pop",
    ],
    [
        [2],
        [1],
        [2],
        [3],
        [4],
        [5],
        [0],
        [20],
        [21],
        [0],
        [2],
        [],
        [],
        [],
        [],
        [],
    ],
    [DinnerPlates]
);

// see example

results compare

please use nodejs assert to confirm the result is right.