|
|
|
|
|
|
|
|
|
|
不知是有被我安利到還是感興趣台灣的人本身很多,遇到許多向我要攻略的小夥伴(為什麼當初卻沒人有空陪我去,還被放過鴿子,罰你們交五毛錢稿費啦ww)。不過話說回來其實自己本來也期待一個人遠行一次,可以得到鍛煉,同時跟世界的接觸面積更大,不會局限在同行的小圈子裡,也更加自在隨心。一路上得到很多人的關心照顧,謝謝你們。在墾丁和從墾丁到花蓮路上陪伴我的四位學長學姐、旅行途中認識或通過網路認識的幾位觀光客都和我一樣,回大陸前每個人都感到悲傷、不捨、希望留下,這大概就是台灣的魅力吧。
下面先上乾貨——
class Solution(object):
def calculate(self, s):
"""
:type s: str
:rtype: int
"""
tokens = ["+", "-", "*", "/"]
token1 = ["+", "-"]
token2 = ["*", "/"]
operators = []
operands = []
res = 0
cur = 0
for x in range(len(s)):
if s[x] in tokens:
operators.append(int(s[cur:x]))
if len(operators) < 2:
operands.append(s[x])
else:
if operands[-1] in token2:
tmp = cal(operands[-1], operators[-2], operators[-1])
operators = operators[:-2]
operators.append(tmp)
operands = operands[:-1]
elif operands[-1] in token1 and s[x] in token1:
tmp = cal(operands[0], int(operators[0]), int(operators[1]))
operators = operators[1:]
operators[0] = tmp
operands = operands[1:]
operands.append(s[x])
cur = x+1
if x == len(s) - 1:
operators.append(int(s[cur:]))
if len(operands) != 0 and operands[-1] in token2:
tmp = cal(operands[-1], int(operators[-2]), int(operators[-1]))
operators = operators[:-2]
operators.append(tmp)
operands = operands[:-1]
while len(operands) != 0 or len(operators) != 0:
if len(operators) == 1 and len(operands) == 0:
return operators[0]
tmp = cal(operands[0], int(operators[0]), int(operators[1]))
operators = [tmp] + operators[2:]
operands = operands[1:]
def cal(operand, operator1, operator2):
if operand == "+":
return operator1 + operator2
if operand == "-":
return operator1 - operator2
if operand == "*":
return operator1 * operator2
if operand == "/":
return operator1 / operator2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
趁着记忆还热,写下来这段日子是如何度过的吧。比较少写经验贴;我的备考过程和我的行事风格常常都是比较个性化而且只想做好眼前,没有提前做好宏伟计划并笃定执行的本事。这篇帖子仅供参考,没有四海皆准的methodology,但一些经验很可能有帮助。先说一下背景,我六月23日一战154+170+3.0,10月30日二战162+170+?,英语基础不错。十月初在家休养,陆续背了一些单词,复习从10.13正式开始。
|
|