From a11fe7128b863154b95807f066e587038418bd78 Mon Sep 17 00:00:00 2001 From: Sumit Sharma <73477380+sumit16sharma@users.noreply.github.com> Date: Wed, 12 Apr 2023 22:38:40 +0530 Subject: [PATCH] Create 0071-simplify-path.java Given a string path, which is an absolute path (starting with a slash '/') to a file or directory in a Unix-style file system, convert it to the simplified canonical path. In a Unix-style file system, a period '.' refers to the current directory, a double period '..' refers to the directory up a level, and any multiple consecutive slashes (i.e. '//') are treated as a single slash '/'. For this problem, any other format of periods such as '...' are treated as file/directory names. The canonical path should have the following format: The path starts with a single slash '/'. Any two directories are separated by a single slash '/'. The path does not end with a trailing '/'. The path only contains the directories on the path from the root directory to the target file or directory (i.e., no period '.' or double period '..') Return the simplified canonical path. I/P : ""/a//b////c/d//././/.."" O/P : "/a/b/c" --- java/0071-simplify-path.java | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 java/0071-simplify-path.java diff --git a/java/0071-simplify-path.java b/java/0071-simplify-path.java new file mode 100644 index 000000000..d1aad8659 --- /dev/null +++ b/java/0071-simplify-path.java @@ -0,0 +1,38 @@ +class Solution { + public String simplifyPath(String path) { + Stack stack = new Stack<>(); + StringBuilder curr = new StringBuilder(); + + String newPath = path + "/"; + + for(int i=0;i pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy