leetcode算法python基礎結構

各類型題需要記住的東西

1. 數組

  1. 注意常用的導入方法(類字典)
    from collections import Counter
    dict = Counter(x)
  2. python自帶排序 — 逆序 多個關鍵字
    list.sort(reverse=True, key=lambda x:(x[0],x[1]))

2. 字符串

  1. 也可以用#數組#的Counter的當如方法
  2. 以什麼字符開始:j.startswith(res) 結束類似 endswith
  3. 注意字符串各大方法 需要返回結果

3. 鏈表

  1. 注意他的結構
	# Definition for singly-linked list.
	# class ListNode:
	#     def __init__(self, x):
	#         self.val = x
	#         self.next = None

4. 樹

  1. 注意他的結構
	# Definition for a binary tree node.
	# class TreeNode:
	#     def __init__(self, x):
	#         self.val = x
	#         self.left = None
	#         self.right = None
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章