Stack Implementation for Simplifying Path

Day 43 of 365 days of code Qn 1) simplify path approach used: stack initialize a stack 1) iterate the string path using var i from 0 to len(path) 2) ignore forward slashes 3) initialize ch="" 4) while i<len(path) and path[i] not equal to forward slash: ch+=path[i];i+=1 5) if ch==.. stack.pop elif ch== . continue else: stack.push(ch) 6)i+=1 7) pop all the element of the stack and put them in another stack 8) initialize a string starting with/ as u iterate pop the stack and add the forward slash to the popped string. #365daysOfCode #NeetCode #leetcode #DSA #python #LeetCode #ProblemSolving #Algorithms

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories