auto commit
This commit is contained in:
@ -223,14 +223,14 @@ Output:
|
||||
|
||||
在字符串尾部填充任意字符,使得字符串的长度等于替换之后的长度。因为一个空格要替换成三个字符(%20),因此当遍历到一个空格时,需要在尾部填充两个任意字符。
|
||||
|
||||
令 P1 指向字符串原来的末尾位置,P2 指向字符串现在的末尾位置。P1 和 P2从后向前遍历,当 P1 遍历到一个空格时,就需要令 P2 指向的位置依次填充 02%(注意是逆序的),否则就填充上 P1 指向字符的值。
|
||||
令 P1 指向字符串原来的末尾位置,P2 指向字符串现在的末尾位置。P1 和 P2 从后向前遍历,当 P1 遍历到一个空格时,就需要令 P2 指向的位置依次填充 02%(注意是逆序的),否则就填充上 P1 指向字符的值。
|
||||
|
||||
从后向前遍是为了在改变 P2 所指向的内容时,不会影响到 P1 遍历原来字符串的内容。
|
||||
|
||||
```java
|
||||
public String replaceSpace(StringBuffer str) {
|
||||
int P1 = str.length() - 1;
|
||||
for (int i = 0; i < P1 + 1; i++)
|
||||
for (int i = 0; i <= P1; i++)
|
||||
if (str.charAt(i) == ' ')
|
||||
str.append(" ");
|
||||
|
||||
@ -385,6 +385,7 @@ private TreeNode reConstructBinaryTree(int[] pre, int preL, int preR, int inL) {
|
||||
|
||||
```java
|
||||
public class TreeLinkNode {
|
||||
|
||||
int val;
|
||||
TreeLinkNode left = null;
|
||||
TreeLinkNode right = null;
|
||||
@ -510,6 +511,7 @@ public int Fibonacci(int n) {
|
||||
|
||||
```java
|
||||
public class Solution {
|
||||
|
||||
private int[] fib = new int[40];
|
||||
|
||||
public Solution() {
|
||||
@ -956,7 +958,7 @@ private void printNumber(char[] number) {
|
||||
|
||||
```java
|
||||
public ListNode deleteNode(ListNode head, ListNode tobeDelete) {
|
||||
if (head == null || head.next == null || tobeDelete == null)
|
||||
if (head == null || tobeDelete == null)
|
||||
return null;
|
||||
if (tobeDelete.next != null) {
|
||||
// 要删除的节点不是尾节点
|
||||
|
Reference in New Issue
Block a user