您是否是靠谱的程序员?
时常耳闻、围观程序员的各种吐槽,有抱怨加班的导致没有个人时间的,有抱怨工作上没有技术含量,整天CRUD,更有抱怨活多工资低,用句时髦的话说“拿着卖白菜的钱,操着卖白粉的心”,用自嘲的口吻说“码农”,有肠子都悔青入错行的大有人在吧?
然,扪心自问,反省,本身的价值有多大?是否是真正意义上的靠谱程序员?相信对于这个命题,也许太过广泛,可以多维度的大谈特谈,比如可以从代码质量、解决问题能力、解决问题方案等等来个几十大条。可我却想从解决问题的方案层面上谈谈,算抛砖引玉罢。
然,扪心自问,反省,本身的价值有多大?是否是真正意义上的靠谱程序员?相信对于这个命题,也许太过广泛,可以多维度的大谈特谈,比如可以从代码质量、解决问题能力、解决问题方案等等来个几十大条。可我却想从解决问题的方案层面上谈谈,算抛砖引玉罢。
一个简单的问题:求2个集合的交集。(集合的存储形式可以是记录表、数组等容器就行)
input_1:1,5,20,11,10,170,50,200,100
input_2:100,50,30,15,150,80,200,48
out:100,50,200
对于上述的问题,按照本人从高中开始程序设计的路线而言,依稀记得用过过以下解决问题的方案:input_2:100,50,30,15,150,80,200,48
out:100,50,200
1> 一种非常直白的方法,对这2个集合遍历一次,就能找到交集数据。代码如下(Python):
input_1 = [1,5,20,11,10,170,50,200,100]
input_2 = [100,50,30,15,150,80,200,48]
def one():
out = []
for input_1_item in input_1:
for input_2_item in input_2:
if input_1_item == input_2_item:
out.append(input_1_item)
return out
if __name__ == "__main__":
print one()
input_2 = [100,50,30,15,150,80,200,48]
def one():
out = []
for input_1_item in input_1:
for input_2_item in input_2:
if input_1_item == input_2_item:
out.append(input_1_item)
return out
if __name__ == "__main__":
print one()
2> 后来,听说hashtable,因此也有过这种写法,利用hashtable的特性。代码如下(Python):
def two():
out = {}
for input_1_item in input_1:
out[str(input_1_item)] = out.get(str(input_1_item), 0) + 1
for input_2_item in input_2:
out[str(input_2_item)] = out.get(str(input_2_item), 0) + 1
return [int(k) for k,v in out.items() if v > 1]
if __name__ == "__main__":
print two()
out = {}
for input_1_item in input_1:
out[str(input_1_item)] = out.get(str(input_1_item), 0) + 1
for input_2_item in input_2:
out[str(input_2_item)] = out.get(str(input_2_item), 0) + 1
return [int(k) for k,v in out.items() if v > 1]
if __name__ == "__main__":
print two()
3> 后来的后来,接触算法分析后,也有过这种写法,先排序,使之成为有规划的数据。代码如下(Python):
def three():
out = []
input_1.sort()
input_2.sort()
point_1 = 0
point_2 = 0
while point_1 < len(input_1) and point_2 < len(input_2):
if input_1[point_1] == input_2[point_2]:
out.append(input_1[point_1])
point_1 += 1
point_2 += 1
elif input_1[point_1] < input_2[point_2]:
point_1 += 1
else:
point_2 += 1
return out
if __name__ == "__main__":
print three()
out = []
input_1.sort()
input_2.sort()
point_1 = 0
point_2 = 0
while point_1 < len(input_1) and point_2 < len(input_2):
if input_1[point_1] == input_2[point_2]:
out.append(input_1[point_1])
point_1 += 1
point_2 += 1
elif input_1[point_1] < input_2[point_2]:
point_1 += 1
else:
point_2 += 1
return out
if __name__ == "__main__":
print three()
4> N次后来,Python内建的集合运算很给力,简单的使用运算符就可以解决此问题,因此也有过这种写法,代码如下(Python):
def four():
return list(set(input_1) & set(input_2))
if __name__ == "__main__":
print four()
对于上述这个问题,我相信您可能在使用上述的某种解决方案,既然出现了多种解决方案,您能否快速明了的说出各种方案的优缺点且适应某种场合呢?我相信作为靠谱的程序员一点压力都没有,简直是玩儿似的。那么您是否是靠谱的程序员呢?return list(set(input_1) & set(input_2))
if __name__ == "__main__":
print four()
推荐(
反对(