import functools
import itertools
from operator import mul
class Solution:
def maximumProduct(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
nums = sorted(nums)
del nums[3:3]
return max(functools.reduce(mul, c) for c in itertools.combinations(nums, 3))
Z
zizhengwu
@zizhengwu
2
Reputation
23
Posts
218
Profile views
0
Followers
0
Following
Posts made by zizhengwu

RE: Python, Straightforward with Explanation

RE: Optimal Division
Could you elaborate on when to add parenthesis in approach #1 and #2?

RE: Ones and Zeroes Python O(m*n*len(strs)) TLE
@1337c0d3r And one more
 Perfect Squares
class Solution(object): def numSquares(self, n): """ :type n: int :rtype: int """ T = [i for i in range(n+1)] perfects = [] i = 1 for n in range(1, n+1): if n == i*i: perfects.append(i*i) i += 1 for p in perfects: T[n] = min(T[n], T[np]+1) return T[n]

RE: Ones and Zeroes Python O(m*n*len(strs)) TLE
@1337c0d3r There are several other problems that suffer from the same dynamic programming Python table construction TLE like:
 Coin Change
class Solution(object): def coinChange(self, coins, amount): """ :type coins: List[int] :type amount: int :rtype: int """ T = [None] * (amount+1) T[0] = 0 for i in range(1, amount+1): for coin in coins: if icoin >= 0 and T[icoin] != None: T[i] = T[icoin] + 1 if T[i] == None else min(T[i], T[icoin]+1) return T[1] if T[1] != None else 1
 Longest Palindromic Substring
class Solution(object): def longestPalindrome(self, s): """ :type s: str :rtype: str """ best = '' T = [[False for __ in range(len(s))] for _ in range(len(s))] for i in range(len(s)): T[i][i] = True best = s[i] for i in range(len(s)): if i + 1 < len(s) and s[i]==s[i+1]: best = s[i:i+2] T[i][i+1] = True for length in range(3, len(s)+1): for i in range(0, len(s)length+1): if T[i+1][i+length11] and s[i] == s[i+length1]: T[i][i+length1] = True best = s[i:i+length] return best

RE: Share my greedy solution
I was wondering why
merge
should take the lexicographical greater one... 
RE: Looks that this is a wrong question. The expected solution didn't consider this case.
Up to
UPDATE: (1:13am)
, an apparently wrong solution could still pass the OJ. Need more test cases. 
What does the test case serialization mean?
For example:
0 [2,null,3] 2
Expected:
2 
RE: Check "Run Code" output
Could you make an enhancement on the problems that DON'T care about the sequence of the output? For example, a straight right or wrong.