leetcode刷题python之H2O的生成

class H2O:
    def __init__(self):
        self.h, self.o = [], []


    def hydrogen(self, releaseHydrogen: 'Callable[[], None]') -> None:
        
        # releaseHydrogen() outputs "H". Do not change or remove this line.
        self.h.append(releaseHydrogen)
        # print(self.h) 函数带括号返回return对应的内容,不带括号是作为函数整体
        self.res()

    def oxygen(self, releaseOxygen: 'Callable[[], None]') -> None:
        
        # releaseOxygen() outputs "O". Do not change or remove this line.
        self.o.append(releaseOxygen)
        # print(self.o)
        self.res()
        
    def res(self):
        if len(self.h) > 1 and len(self.o) > 0:
            self.h.pop(0)()
            self.h.pop(0)()
            self.o.pop(0)()

你可能感兴趣的:(leetcode_python)