@nmbmlyx0211, check how deque works in Python here.
Seasean
@Seasean
Posts made by Seasean

RE: Concise 1 Queue  Java, C++, Python

RE: Easy Python solution O(n)
It is fast, but not space efficient.
Without creating new list instance, we could dodigits.insert(0,1)
instead of[1] + digits

RE: 8line Python solution, dynamic programming, beats 86.77%
any one can figure out the time complexity?

RE: My clean Java solution
just wondering the time and space complexity, anyone? thanks

RE: Python dfs solution.
@qizhu8 to be honest, I still doubt about using sort except using it as for the order for one single answer such as your example, it is better to have [1,1,2] than [1,2,1].
But besides that, the sort is not useful, because the answer [1,1,2] and [1,2,1] will not show twice even not using sort! you could try the custom test case and watch std output. The thought of dfs here is searching with for loop, you will never check the node backward in for loop, so it is strictly removed the duplicates in this way. Also try to check the runtime, there is no difference with and w/o sorting.
In addition, we do not need index parameter, and we can simply use the following solution for easy understanding, faster and remembering:
def combinationSum(self, candidates, target): """ :type candidates: List[int] :type target: int :rtype: List[List[int]] """ res = [] self.rec(candidates,target,[],res) return res def rec(self,candidates,target,path,res): if target < 0: return if target == 0: res.append(path) return for i in xrange(len(candidates)): self.rec(candidates[i:],targetcandidates[i],path+[candidates[i]],res)

RE: Python one liner 48ms
OG binary search, FYI.
def searchInsert(self, nums, target): low = 0 high = len(nums)  1 while low <= high: mid = (low + high) / 2 if nums[mid] == target: return mid elif nums[mid] < target: low = mid + 1 else: high = mid  1 return low

RE: Simple Python DFS solution with explanation
wondering the time complexity?

RE: Simple and clear proof/explanation
This might be more comfortable
l = 0 r = len(height)  1 max_area = 0 while l < r: if height[l] >= height[r]: max_area = max(max_area,height[r]*(rl)) r = 1 else: max_area = max(max_area,height[l]*(rl)) l += 1 return max_area

RE: Python solution based on the algorithm in leetcode blog
I used to write a oneline python soln with trick. Now I think there would be a more general solution for dealing with Palindrome (it might be not as efficient as dealing with numbers, but it is good if you have this in mind to deal with all Palindrome stringtyped questions):
def isPalindrome(self, x): x = str(x) #no need consider the sign, as with "", the result wont be true def palindrome(s,l,r): while l >= 0 and r < len(x) and x[l] == x[r]: l = 1 r += 1 return True if l < 0 else False #either l<0 or r>=len(x) return true if len(x)%2 == 0: l = len(x)/2  1 r = len(x)/2 return palindrome(x,l,r) if len(x)%2 != 0: l = r = len(x)/2 return palindrome(x,l,r)