Trick

  1. 避免矩陣邊界

    (j?ones[i][j-1]:0)
    
  2. enumerate不要忘記加

python實現

  1. 其他

  2. 基礎運算

  3. assign a = b = target

  4. for 用法大小事

    for i in range(5): # 0~4
    for i in range(5, 0, -1) # 5~1
    for i in reversed(range(5)): #4~0
    
    w = 10
    for i in range(w):
    	print(i)
    	w += 1
    # 0, 1, 2 ..., 10
    
  5. collections

Python數據結構

  1. list
  2. Dict
  3. set
  4. Queue
  5. Stack
  6. heap

測試

import unittest
class Test(unittest.TestCase):
  def case___(self):
    expectation = ...
    result = call_solution(send_input)
    self.assertEqual(expectation, result)
test = Test()
test.case___()