2016年12月27日

390. Elimination Game - I really didn't expect it working so perfect

最开始的时候,我写的代码是这样的:
nums = range(n, 0, -1)

while len(nums) > 1:
    nums = nums[-2::-2]

毫无疑问,虽然答案对了,但是内存爆了。

于是搜了下其他人的答案,知道了思路是找左右点。然后有了下面的代码:
left, length ,step = 1, n, 1
right = left + (n - 1) * step

while length > 1:
    left += step        # Drop the first
    step <<= 1
    length >>= 1
    right = left + (length - 1) * step          # Get the right point.

    left, right = right, left
    step = ~step + 1

扔到PyCharm里调试,并和上面那个结果做Assert,居然完美通过,然后我就木凳狗带了——妈蛋我自己都只有个大概思路就撸了啊,没想到居然没什么错,这和我一贯以来20%的通过率不符啊……


2016年12月1日

312. Burst Balloons 继续趟pytho的坑……

这次被坑的是初始化二维数组……

[[0] * size] * size != [[0] * size for i in range(size)] == [[0 for i in range(size)] for i in range(size)]

然后读了读 http://ars.me/programming/2014/06/14/py-listmul/ 妥了……

2016年11月30日

花了差不多一下午补DP相关的东西,终于勉强做完了377. Combination Sum IV

在思路上绕了好久,最后还是没解决,忍不住去搜索了。然后发现是自己不擅长的DP,花了差不多整个下午,终于能勉强答题了。

class Solution(object):
    def combinationSum4(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: int
        """
        dp = [1] + [0] * target
        
        for i in range(target + 1):
            for num in nums:
                if i + num <= target:
                    dp[i + num] += dp[i]
        
        return dp[target]

答完题回来看看,似乎确实不难啊……

2016年11月17日

378. Kth Smallest Element in a Sorted Matrix的附带收获

神之多重list展开:

matrix_expanded = [element for line in matrix for element in line]

这很Python,写了两个for循环的我给跪了……

2016年11月9日

406. Queue Reconstruction by Height 的Python解法

研究了好久算法,最后参考了别人的思路,才发现代码可以这么简单……

思路总结:
1. 预排序,h从大到小,k从小到大
2. 依次把每个元素插到新list的k位置

class Solution(object):
    def reconstructQueue(self, people):
        """
        :type people: List[List[int]]
        :rtype: List[List[int]]
        """
        result = []
        
        people.sort(key = operator.itemgetter(1))
        people.sort(key = operator.itemgetter(0), reverse = True)
        
        for p in people:
            result.insert(p[1], p)
            
        return result

这样的思路实现起来,真的很简单啊!

2016年10月18日

脱单5个月

军团远征已开。
已经在Kabam上班3个月。
国庆长假已经过去。

还是感觉很幸福。

2016年5月18日

2016.5.17,脱单

ღ(๑╯◡╰๑ღ)

2016年4月28日

更新后的工作经历

2007.9.12 - 2012.4.27 Gameloft 智乐软件
2012.8.20 - 2012.9.6 Beyond Soft 博彦科技
2012.10.8 - 2013.4.24 Dreamingame 追梦创新
2013.6.26 - 2013.12.12 Renren Games 人人游戏
2013.12.16 - 2016.4.27 Glu mobile 格融科技

2016年4月23日

不知不觉,魔兽世界的第七个资料片也快来了

所以,又到了写副本杂谈的时候了么……