public class Solution { public string SimplifyPath(string path) { var folders = path.Split('/').Where(x=>x!=. && x != / && x != ).ToList(); var stack = new Stack(); for(var i = 0;i < folders.Count; i++){ if(folders[i] == ..){ if(stack.Count > 0){ stack.Pop(); } } else{ stack.Push(folders[i]); } } var result = string.Empty; while(stack.Count > 0){ var f = stack.Pop(); result = string.Format(/{0},f) + result; } if(result == string.Empty){ return /; } return result; } }