mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-22 00:43:42 +00:00
auto commit
This commit is contained in:
+22
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user