package com.fishercoder.solutions;

import java.util.Arrays;
import java.util.Deque;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;

/**
 * 71. Simplify Path

 Given an absolute path for a file (Unix-style), simplify it.

 For example,
 path = "/home/", => "/home"
 path = "/a/./b/../../c/", => "/c"

 Corner Cases:
 Did you consider the case where path = "/../"?
 In this case, you should return "/".
 Another corner case is the path might contain multiple slashes '/' together, such as "/home//foo/".
 In this case, you should ignore redundant slashes and return "/home/foo".
 */
public class _71 {

  public static class Solution1 {
    public String simplifyPath(String path) {
      Deque<String> stack = new LinkedList<>();
      Set<String> skipSet = new HashSet<>(Arrays.asList("..", ".", ""));
      for (String dir : path.split("/")) {
        if (dir.equals("..") && !stack.isEmpty()) {
          stack.pop();
        } else if (!skipSet.contains(dir)) {
          stack.push(dir);
        }
      }
      String result = "";
      for (String dir : stack) {
        result = "/" + dir + result;
      }
      return result.isEmpty() ? "/" : result;
    }
  }
}

@@ -160,457 +160,8 @@
 t;%0A%0A
-/**%0A * 71. Simplify Path%0A%0A Given an absolute path for a file (Unix-style), simplify it.%0A%0A For example,%0A path = %22/home/%22, =%3E %22/home%22%0A path = %22/a/./b/../../c/%22, =%3E %22/c%22%0A%0A Corner Cases:%0A Did you consider the case where path = %22/../%22?%0A In this case, you should return %22/%22.%0A Another corner case is the path might contain multiple slashes '/' together, such as %22/home//foo/%22.%0A In this case, you should ignore redundant slashes and return %22/home/foo%22.%0A */%0A
 publ
@@ -176,16 +176,18 @@
  _71 %7B%0A%0A
+  
   public
@@ -212,24 +212,28 @@
 tion1 %7B%0A    
+ 
+   
 public Strin
@@ -268,16 +268,22 @@
 %7B%0A      
+ 
+     
 Deque%3CSt
@@ -322,16 +322,22 @@
 ;%0A      
+    
+  
 Set%3CStri
@@ -395,16 +395,22 @@
 , %22%22));%0A
+      
       fo
@@ -452,16 +452,24 @@
         
+ 
+       
 if (dir.
@@ -500,24 +500,34 @@
 sEmpty()) %7B%0A
+          
           st
@@ -533,24 +533,32 @@
 tack.pop();%0A
+        
         %7D el
@@ -586,24 +586,34 @@
 ins(dir)) %7B%0A
+          
           st
@@ -627,16 +627,24 @@
 h(dir);%0A
+        
         
@@ -651,24 +651,36 @@
 %7D%0A      
+ 
-%7D%0A
+     %7D%0A   
       
+   
 String r
@@ -691,16 +691,22 @@
 t = %22%22;%0A
+      
       fo
@@ -726,24 +726,32 @@
  : stack) %7B%0A
+        
         resu
@@ -777,26 +777,38 @@
 sult;%0A      
+ 
-%7D%0A
+     %7D%0A      
       return
@@ -845,16 +845,22 @@
 lt;%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 71