public
class
lc07
}return
(int
) res;
}//方法二:不用long
public
intreverse2
(int x)
res = temp;
x /=10;
}return res;
}}
public
class
t_44_reversesentence
string[
] word = str.
split
(" ");
stringbuilder res =
newstringbuilder()
;for
(int i = word.length -
1; i >
0; i--
) res.
(word[0]
);return res.
tostring()
;}}
stringbuilder 內部有 reverse 方法
trim 表示去掉字串兩端的多餘空格
public
class
lc557
return res.
tostring()
.trim()
;}}
public
class
t_15_reverselist
return pre;
}//遞迴寫法
public listnode reverselistrec
(listnode head)
listnode p =
reverselistrec
(head.next)
; head.next.next = head;
head.next = null;
return p;
}public
class
listnode
}}
public
class
lc92
listnode cur = head;
listnode pre = null;
while
(m >1)
listnode con = pre;
listnode tail = cur;
listnode next;
while
(n >0)
if(con != null)
else
tail.next = cur;
return head;
}}
public
class
lc344
}}
public
class
lc345
hashset
vowels =
newhashset
<
>
(arrays.
aslist
('a'
,'e'
,'i'
,'o'
,'u'
,'a'
,'e'
,'i'
,'o'
,'u'))
;int i =0;
int j = s.
length()
-1;char
res =
newchar
[s.length()
];while
(i <= j)
elseif(
!vowels.
contains
(cj)
)else
}return string.
valueof
(res);}
}
思路:反轉k個,跳過k個,最後剩餘的不夠k個,全部反轉
public
class
lc541
else
if(i + k <= arr.length)
else
i +=
2* k;
}return string.
valueof
(arr);}
private
void
reversearr
(char
arr,
int from,
int end)
}}
public
class
lc917
res.
(s.charat
(j--))
;}else
}return res.
tostring()
;}}
輸入:s = 「(u(love)i)」
輸出:「iloveu」
思路:用棧來記錄左括號。
public
class
lc1190
if(arr[i]
==')')}
for(
char c : arr)
}return sb.
tostring()
;}private
void
reverse
(char
arr,
int l,
int r)
}}
鍊錶之反轉系列
leetcode206 easy 反轉全部的單鏈表,遞迴和非遞迴版本!package linkedlist public class main0206反轉鍊錶 迭代 class solution206 return pre 遞迴 class solution0206 反轉雙向鍊錶 class sol...
nginx 跳轉系列
2 根據remote addr 流量及if的或匹配 或匹配 3 根據header 流量 4 if實現 與 操作 nginx不支援shell的and 實現,也不支援if巢狀,所以採用設定變數的方式實現。首先設定乙個變數置為空 set flag 0 然後根據條件追加值,在最終的if塊中根據 flag的值...
演算法系列之三 單鏈表反轉
問題 實現單鏈表反轉 答案 鍊錶準備 class node public int getdata public void setdata int data public node getnext public void setnext node next public static void mai...