<aside> ✍️ Key Points:
经典题型:
什么时候想到用Stack去解决String题?
Good Code-Writing Examples
Two Pointers 模版
while (fast < len) {
if keeping, copy fast to slow, slow++ fast++
else (discarding) fast++
}
return new String(charArray, 0, slow)
// while loop里考虑在不同情况下,fast怎么动,slow怎么动
// fast和slow的初始值可以节省edge case,让代码简介. (slow = 1 and fast = 1 at Remove All Adjacent Duplicates In String)
// when discarding, we can set some additional condition (i.e. while loop) to remove a block of unnecessary elements more efficiently.
// 遍历方向: 没必要一定要让fast从左到右的移动。方便时也可以从右到左 - String Replacement (replace longer)
Other Tips </aside>
<aside> 📌 易错点
+1
or -1
String APIs
new String(char[] value, int offset, int count) //(charArr, startIndex, subArrLen)
str.substring(int beginIndex, int endIndex) // including startIndex, excluding endIndex
a
sb.length() // StringBuilder‘s size
sb.charAt(i) // not sb.get(i)
sb.delete(int startingIndex, int lengthToDelete)
sb.deleteCharAt(i)
sb.append()
sb.toString()
sb.reverse()
Character.isDigit(char ch)
Character.isAlphabet(char ch)
<aside> 🌵 Table of Contents
</aside>
Date: July 14, 2023
Date: July 14, 2023
Date: July 14, 2023
Date: July 14, 2023