常用的数据结构定义

# Definition for singly-linked list.
class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None


class DoubleNode(object):
    def __init__(self, key, val, pre=None, next=None):
        self.key = key
        self.val = val
        self.pre = pre
        self.next = next


# Definition for a binary tree node.
class TreeNode(object):
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class TrieNode(object):
    def __init__(self, end=False):
        self.children = []
        for i in range(26):
            self.children.append(None)
        self.end = end

    def set_end(self):
        self.end = True

    @property
    def is_end(self):
        return self.end


class RandomNode(object):
    def __init__(self, val, next, random):
        self.val = val
        self.next = next
        self.random = random


class GraphNode(object):
    def __init__(self, val, neighbors):
        self.val = val
        self.neighbors = neighbors

全部评论

相关推荐

11-19 18:44
已编辑
成都理工大学 Java
程序员花海:我面试过100+校招生,大厂后端面试不看ACM,竞赛经历含金量低于你有几份大厂实习 这个简历整体来看不错 可以海投
如何写一份好简历
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务