Stack

Stack 是一種「後進先出 LIFO」的容器 (Last if First Out),適用於需要紀錄之前的狀態或是值的情況,必要的時候可以回到之前的樣子。對於 Java 和 Python 的 Stack 使用可以記憶一下:

  • Java 推薦是雙端隊列 Deque 取代 Stack
  • Python 更簡單的可直接將 List 作為 Stack 使用

Continue reading

把 List of array 轉成 2D-array

List<T[]> list = new ArrayList();
// 記得 list.size()
// 後面還有個[]
T result[][] = list.toArray(new T[list.size()][]);

// 實際 example
List<int[]> listOfIntegers = List.of( new int[] { 1, 2 }, new int[] { 3, 55, 65 } );
int[][] array2D = listOfIntegers.toArray( new int[listOfIntegers.size()][] );

Continue reading

Author's picture

李昀陽 YunYang Lee

Welcome to my Tech Note. You can read some of the chapters below.

Software Engineer

Taiwan