Try to solve problems in JavaScript, Python, and Java.
This is TIL(memo of key learnings) for solving problems in these languages,
but mostly python.

241205:
1. 0101-symmetric-tree
2. 0102-binary-tree-level-order-traversal
Easy, you can check if a current node is None.
if treeNode is None:
array[index] exists? before appending a value in python?binary-tree-level-order-traversal
When working with a 2-dimensional array, attempting to append a value to a non-existent index results in an error.
To avoid this, you can check the length📏 of the array to ensure the target(array[index]) index exists.
# Case: 'level' represents the depth of the binary tree node.
result = []
...
if len(result) <= level:
result.append([]) # add a new list for the current level.
result[level].append(node.val)
List<List<Integer>>List<List<Integer>> nestedList = new ArrayList<>();
List<int> and int[] in Java?| Aspect | int[] | List<Integer> |
|---|---|---|
| Size | Fixed | Dynamic |
| Type | Primitive int | Wrapper Integer |
| Memory | More efficient (no object overhead) | Higher (due to object overhead) |
| Performance | Faster | Slower (boxing/unboxing) |
| Resizing | Not resizable | Resizable |
new ArrayList<>(), not [] in java?In Java, List is an interface, so you cannot directly instantiate it!
must use a concrete implementation like ArrayList, [] is not a valid way.
List<List<Integer>> result = new ArrayList<>();
ArrayList?ArrayList is a dynamic array implementation of the List interface in Java, provided by the java.util package.
Boxing and Unboxing refer to the automatic conversion between primitive types and corresponding wrapper class objects.
Add a slight overhead because the Java Virtual Machine (JVM), create new objects for primitive values & convert objects back into primitives.
int num = 5;
Integer boxedNum = num; // Automatic boxing
int unboxNum = boxedNum; // Automatic unboxing
List<Integer>