auto commit

This commit is contained in:
CyC2018
2018-02-27 15:03:36 +08:00
parent fb1f12fef0
commit b3b0fdd727
+22 -1
View File
@@ -147,7 +147,11 @@ public boolean Find(int target, int [][] array) {
**题目要求**
以 O(1) 的空间复杂度来求解。
以 O(1) 的空间复杂度和 O(n) 的空间复杂度来求解。
**解题思路**
从后向前改变字符串。
```java
public String replaceSpace(StringBuffer str) {
@@ -188,6 +192,23 @@ public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
}
```
使用 Stack
```java
public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
Stack<Integer> stack = new Stack<>();
while (listNode != null) {
stack.add(listNode.val);
listNode = listNode.next;
}
ArrayList<Integer> ret = new ArrayList<>();
while (!stack.isEmpty()) {
ret.add(stack.pop());
}
return ret;
}
```
递归
```java