注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
本菜鸡最近投了一家才成立了几个月的公司(小到都google不到那种), 给发了一个take home project, 找了好几个月工作了因为太菜也没有几个面试机会, 所以想认认真真的把这个做了... 奈何能力还是太浅, 真心求各位大佬给建议:
给了一段python code: 包含一个全局叫document和一个hashset叫dictionary, define了几个基础function: copy(i), paste(i,j), cut(i,j), misspellings(). i,j指的是要copy/paste到document的位置. 逻辑很直白, 问的是如何优化performance. 主要code贴在下面了. 目前能想到的优化就是1. copy的时候只记录i和j而不是存一整段copied的内容. 2. (maybe)Document的内容用doubly linkedlist存来加快delete/insert的速度. 用一个hashmap存index和对应的node. 题目要求说是一个开放性问题, 希望大佬们能给点提示!!
给的主要code:.google и
class SimpleEditor:
def __init__(self, document):
self.document = document
self.dictionary = set()
with open("...\words") as input_dictionary:
for line in input_dictionary:. From 1point 3acres bbs
words = line.strip().split(" ")
for word in words:
self.dictionary.add(word)
self.paste_text = ""
def cut(self, i, j):
self.paste_text = self.document[i:j]
self.document = self.document[:i] + self.document[j:]
def copy(self, i, j):
self.paste_text = self.document[i:j]. Χ
. 1point 3acres
def paste(self, i):
self.document = self.document[:i] + self.paste_text + self.document[i:]
.google и
def misspellings(self): #check number of misspellings in the document
result = 0
for word in self.document.split(" "):
if word not in self.dictionary:
result = result + 1
return result
. ----
|