目录
1544. 整理字符串
class Solution {
public String makeGood(String s) {
StringBuilder arr = new StringBuilder(s);
char a;
char b;
int len = arr.length();
for (int i = 0; i < len-1; i++) {
a = arr.charAt(i);
b = arr.charAt(i+1);
if ((a ^ b) == 32){
arr.delete(i,i+2);
if (i == 0) i = -1;
else i -= 2;
len -= 2;
}
}
return arr.toString();
}
}
141. 环形链表
// 快慢指针在链表循环中一定哟啊多加一个,不然追不上
public class Solution {
public boolean hasCycle(ListNode head) {
// 边界条件
if(head==null|| head.next==null){
return false;
}
//定义快慢指针
ListNode s=head;
ListNode f=head.next;
while(s!=f){
// 如果不存在环形链表,直接为空,怎么办
if(f==null||f.next==null){
return false;
}
s=s.next;
f=f.next.next;
}
return true;
}
}