var moveZeroes = function(nums) {
var len = nums.length;
for (var i = 0; i<len; ++i){
if (nums[i]===0){
nums.splice(i,1);
nums.push(0);
i;
len;
}
}};
M
MinhuiZheng
@MinhuiZheng
5
Reputation
13
Posts
139
Profile views
1
Followers
0
Following
Posts made by MinhuiZheng

JavaScript Accepted O(n) Solution

RE: My Concise Python Solution 52ms
Time Complexity O(n) Space Complexity O(1)

My Concise Python Solution 52ms
class Solution(object): def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ if not prices: return 0 buy = prices[0] profit = 0 for i in xrange(1,len(prices)): if prices[i] < buy: buy = prices[i] profit = max(profit, prices[i] buy) return profit

RE: One line python solution
Very concise solution! But could you please enlighten me a little bit about the lambda expression, especially the acc? Thanks!

RE: My 44ms solution use str()
Not really. It's kinda like empirical since the happy number less than 10 are 1 and 7.

RE: My python solution
But I'm not sure whether use nums[:] was making a copy of array or not . Can anyone explain it a little bit?

My python solution
class Solution(object): def moveZeroes(self, nums): """ :type nums: List[int] :rtype: void Do not return anything, modify nums inplace instead. """ count = 0 for n in nums[:]: if n == 0: nums.remove(0) count += 1 nums += [0]*count