Leetcode 71: Simplify Path

My original solution (whiteboard notes below) involved manually parsing the directory names by stepping over characters one by one looking for the slash character. This was somewhat fiddly and error prone and required some fixes after trying the test cases. I reimplemented using std::getline() and stringstream to do the tokenising, which proved simpler and less error prone. See gist source code for that implementation below.

Here’s the source code for that initial solution:
https://gist.github.com/adamkorg/36adeab8156778d3852c37a57fb250aa

And here’s the source code for the simplified getline()/stringstream solution:

This entry was posted in programming and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *