之前一直不知道 Java 的 ArrayList 有 add(int index, E element), Inserts the specified element at the specified position in this list.
这个方法。
如果使用 add(0, element), 就相当于把元素一直插入到头。 就免去了reverse的过程。
之前不知道可以这样,都是使用 add(element), 然后翻转一次
之前一直不知道 Java 的 ArrayList 有 add(int index, E element), Inserts the specified element at the specified position in this list.
这个方法。
如果使用 add(0, element), 就相当于把元素一直插入到头。 就免去了reverse的过程。
之前不知道可以这样,都是使用 add(element), 然后翻转一次