印度小哥斯坦福但是没有口音!和之前一位仁兄发过的面经一模一样!就是p e r s i s t a n t 堆 s t ac k
但是我实现下来感觉没有那么复杂 就类似用个linkedlist一样的structure就行了
需要设计constructor,peek,pop,size
然后还要test,run最后好不容易过了哈哈
想請教lz什麼是persistant 堆 stack?
用linkedlist 來實作stack嗎?還是什麼
感謝lz
你给个邮箱我直接全部发给你吧
http://www.1point3acres.com/bbs/thread-233854-1-1.html
补充内容 (2018-2-28 04:50):
参考这位写的帖子 描述的很详细了
好的 我來看一下:)
我和楼主感觉差不多呀 是不是那个仁兄想复杂了
lz最后结果怎么样呢
求问楼主电面怎么准备, 有没有靠谱面经哇。。。下周面试,没想到这家这么难
我写了个python的版本
import unittest
class PStack:
def __init__(self, prev=None, value=None, size=0):
self.prev = prev
self.value = value
self.size = size
def push(self, x):
return PStack(self, x, self.size + 1)
def pop(self):
return self.prev
def peek(self):
return self.value
def getSize(self):
return self.size
class PStackTest(unittest.TestCase):
def testPstack(self):
pstack = PStack()
s1 = pstack.push(1)
s2 = pstack.push(2)
s3 = s2.push(3)
tmp = s3.pop()
self.assertEqual(0, pstack.getSize())
self.assertEqual(1, s1.getSize())
self.assertEqual(1, s1.peek())
self.assertEqual(1, s2.getSize())
self.assertEqual(2, s2.peek())
self.assertEqual(3, s3.peek())
self.assertEqual(2, s3.getSize())
self.assertEqual(tmp, s2)
if __name__ == "__main__":
unittest.main()
最新 电面
Given an input list of names, for each name, find the shortest substring that only appears in that name.
Example:
Input: ["cheapair", "cheapoair", "peloton", "pelican"]
Output:
"cheapair": "pa" // every other 1-2 length substring overlaps with cheapoair
"cheapoair": "po" // "oa" would also be acceptable
"pelican": "ca" // "li", "ic", or "an" would also be acceptable
"peloton": "t" // this single letter doesn't occur in any other string