Title: #71 - Simplify Path - LeetCode JavaScript Solutions
Open Graph Title: #71 - Simplify Path - LeetCode JavaScript Solutions
X Title: #71 - Simplify Path - LeetCode JavaScript Solutions
Description: You are given an absolute path for a Unix-style file system, which always begins with a slash '/'. Your task is to transform this ...
Open Graph Description: You are given an absolute path for a Unix-style file system, which always begins with a slash '/'. Your task is to transform this ...
X Description: You are given an absolute path for a Unix-style file system, which always begins with a slash '/'. Your task is to transform this ...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/simplify-path
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/simplify-path","name":"#71 - Simplify Path - LeetCode JavaScript Solutions","description":"You are given an absolute path for a Unix-style file system, which always begins with a slash '/'. Your task is to transform this ...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {string} path\n * @return {string}\n */\nvar simplifyPath = function(path) {\n const stack = [];\n for (const segment of path.split('/')) {\n if (segment === '.' || segment === '') continue;\n if (segment === '..') stack.pop();\n else stack.push(segment);\n }\n return `/${stack.join('/')}`;\n};","keywords":"LeetCode 71, #71 - Simplify Path, Medium, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/simplify-path |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/simplify-path/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0071-simplify-path.js |
| String | https://leetcodejavascript.com/tags/string |
| Stack | https://leetcodejavascript.com/tags/stack |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width,initial-scale=1
Robots: index, follow