All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com_github_leetcode.ListNode Maven / Gradle / Ivy

package com_github_leetcode;

@SuppressWarnings("java:S1104")
public class ListNode {
    public int val;
    public ListNode next;

    public ListNode() {}

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder("" + val);
        ListNode current = next;
        while (current.next != null) {
            result.append(", ");
            result.append(current.val);
            current = current.next;
        }
        result.append(", ");
        result.append(current.val);
        return result.toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy