LeetCode 271: Length-Prefixed String Encoding

Solved "Encode and Decode Strings" (LeetCode 271) The trick? Use a length-prefixed encoding: <length>#<string> For example: ["lint","code"] → "4#lint4#code" Why this works: The length tells the decoder exactly how many characters to read No delimiter conflicts — even if the string itself contains # or digits O(n) time and space A clean example of how a simple idea can handle all edge cases elegantly. #leetcode #dsa #python #problemsolving

To view or add a comment, sign in

Explore content categories