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

com_github_leetcode.Node.kt Maven / Gradle / Ivy

There is a newer version: 1.30
Show newest version
package com_github_leetcode

import java.util.StringJoiner
import kotlin.collections.ArrayList

class Node {
    var `val`: Int
    var neighbors: List

    constructor() {
        `val` = 0
        neighbors = ArrayList()
    }

    constructor(`val`: Int) {
        this.`val` = `val`
        neighbors = ArrayList()
    }

    constructor(`val`: Int, neighbors: List) {
        this.`val` = `val`
        this.neighbors = neighbors
    }

    override fun toString(): String {
        val result = StringJoiner(",", "[", "]")
        for (node in neighbors) {
            if (node.neighbors.isEmpty()) {
                result.add(node.`val`.toString())
            } else {
                val result2 = StringJoiner(",", "[", "]")
                for (nodeItem in node.neighbors) {
                    result2.add(nodeItem.`val`.toString())
                }
                result.add(result2.toString())
            }
        }
        return result.toString()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy