Machine Learning Engineer用Python刷题,该不该用builtin函数?

Machine Learning Engineer用Python刷题,该不该用builtin函数?
刚起步刷LeetCode,目标Machine Learning Engineer,用Python,该不该用builtin函数?
做DS Project时,常用Python的builtin函数,觉得很方便,但刷算法题的时候,似乎感觉应该多practice自己写实现过程的能力,而不是只用builtin函数?

举例说明:LeetCode 27,Remove Element
如果用builtin函数非常简单,39ms
while val in nums:
       nums.remove(val)
return len(nums)
然后看discussion,排名靠前的Python solution是这样的,也是39ms
    start, end = 0, len(nums) - 1
    while start <= end:
           if nums[start] == val:
                   nums[start], nums[end], end = nums[end], nums[start], end - 1
           else:
                   start +=1
    return start
在这里就很纠结:是否应该重点按照后者的思路呢?

欢迎讨论,非常感谢~



20个回复 举报 回复

Sign In to reply

20个回复