-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay02.java
More file actions
50 lines (47 loc) · 1.28 KB
/
Day02.java
File metadata and controls
50 lines (47 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package 比特笔试强训;
import java.util.Stack;
public class Day02 {
public static void main(String[] args) {
String s = "We are happy.";
System.out.println(replaceSpace(s));
}
static class ListNode{
int val;
ListNode next;
public ListNode(){
}
public ListNode(int val){
this.val=val;
}
}
public static int[] reversePrint(ListNode head) {
if (head==null){
return null;
}
ListNode cur = head;
Stack<Integer> stack = new Stack<>();
int count = 0;
while (cur!=null){
stack.push(cur.val);
cur=cur.next;
count++;
}
int[] result = new int[count];
for (int i = 0; i < count; i++) {
result[i]=stack.pop();
}
return result;
}
public static String replaceSpace(String s) {
StringBuilder stringBuffer = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (ch!=' '){
stringBuffer.append(ch);
}else {
stringBuffer.append("%20");
}
}
return stringBuffer.toString();
}
}