美文网首页
61. LeetCode 844. 比较含退格的字符串

61. LeetCode 844. 比较含退格的字符串

作者: 月牙眼的楼下小黑 | 来源:发表于2019-02-14 22:54 被阅读7次

早上和拓哥聊到那个失踪博士的事。

“应该是自...” 拓哥话没说完,但是我俩心知肚明。

我内心抱有一丝侥幸, “看新闻报道说,他失踪前很正常。”

“那你看我正常吗 ?” 拓哥语调突然地高了几分。

我毫不犹豫地说:“你很不正常,我一眼就看出来了,跟我去年的样子一样 ”。

“我这几天每天都起得很早。” 拓哥故作轻松。

“早醒吗? 晚上睡得好吗 ?” 我知道他在经历这些煎熬。

拓哥恢复了一脸的疲惫 : “是的, 两三点才睡着,四五点就醒了” 。

拓哥是博士第三年,理应今年 6 月份毕业 ,但是小实验室发 CV 顶会顶刊谈何容易。没有指导,没有战友的他从去年 11 月份起就变得十分焦虑。 他过完年回来,我看到他第一眼后就知道他感觉很不好,非常不好。

我需要多关爱一下他了。一是绝对不能增加他的焦虑,少问些有的没的。二是多鼓励关注他了,如果他有做傻事的苗头,要及时发现。

在这里,我要再次感谢去年把我从泥潭中拉出来的两个人: 定胡刘宇。从某种程度讲,他们是我的救命恩人了。


  • 标签: 双指针
  • 难度: 简单

  • 题目描述
  • 我的解法

用两个栈解决,很简单,没啥可说的,我丧得一匹。

class MyQueue(object):

    def __init__(self):
        """
        Initialize your data structure here.
        """
        self.list1 = []
        self.list2 = []
        
    def push(self, x):
        """
        Push element x to the back of queue.
        :type x: int
        :rtype: void
        """
        self.list1.append(x)
        

    def pop(self):
        """
        Removes the element from in front of queue and returns that element.
        :rtype: int
        """
        self.peek()
        return self.list2.pop()
        
    def peek(self):
        """
        Get the front element.
        :rtype: int
        """
        if(self.list2 ==[]):
            while(self.list1):
                self.list2.append(self.list1.pop())        
        return self.list2[-1]
        

    def empty(self):
        """
        Returns whether the queue is empty.
        :rtype: bool
        """
        return self.list1 == [] and self.list2 == []
        


# Your MyQueue object will be instantiated and called as such:
# obj = MyQueue()
# obj.push(x)
# param_2 = obj.pop()
# param_3 = obj.peek()
# param_4 = obj.empty()
  • 其他解法

暂略。

相关文章

网友评论

      本文标题:61. LeetCode 844. 比较含退格的字符串

      本文链接:https://www.haomeiwen.com/subject/wvtueqtx.html