String Builder

String is immutable
String concatenation += is expensive

O(n)

Python | Java

String is immutable, meaning you can't change it once created. When you concatenate two strings, it doesn’t simply add one string at the end of another; it creates a new string (ouch). Use a StringBuilder instead (or string.join() on a list in Python), which essentially is a List<Character>.

· String += c linear
·
StringBuilder.append(c) constant

LeetCode

1119. Remove Vowels from a String

Python | Java

Previous
Previous

Deque

Next
Next

Inorder Traversal of a BST