Leetcode 71 Simplify Path (Medium)
I am a developer who loves Java, Spring, Quarkus, Micronaut, Open source, Microservices, Cloud
Search for a command to run...
I am a developer who loves Java, Spring, Quarkus, Micronaut, Open source, Microservices, Cloud
No comments yet. Be the first to comment.
Data Structure & Algorithms : the most important and fundamental of any programmer. We will explore famous questions on datastructure & algorithms from various popular websites.
Question Link : https://leetcode.com/problems/binary-tree-right-side-view/ It is pretty simple explanation if you visualize the tree .If we do level order traversal and keep each level node values in a list (keeping from left to right) the last val...
Spring AI Tool Calling: From Chatbot to AI Agent with @Tool Your AI is smart. It knows an enormous amount. But it's frozen. It doesn't know what time it is right now. It doesn't know what's on your ca
Spring AI Advisors API Explained Series: Spring AI Complete Course — Lecture 4 of 12Reading Time: 8 minutesLevel: Intermediate Most developers stop at ChatClient. That is enough for demos. It is not
Working with Multiple AI Models in Spring AI Spring AI Complete Course — Lecture 3 of 12Previous: Lecture 2 — ChatClient API | Next: Lecture 4 — Advisors API In production AI applications, you rarel
Spring AI ChatClient API: The Fluent Heart of AI Integration Introduction If you've ever tried integrating AI models into a Java application, you know the pain. HTTP clients, API keys scattered everywhere, vendor-specific SDKs that never quite fit. W...
What is Spring AI? — Why Java Developers Need This in 2026 Every AI tutorial you see is in Python. LangChain, LlamaIndex, OpenAI SDK — all Python. But here's the uncomfortable truth: 80% of enterprise backends run Java. So who's building AI into thos...
Question Link : https://leetcode.com/problems/simplify-path/
After reading the question , the first intution is for using stack as appropriate data structure There are two possiblities either you do interate character by character or split the string and find the all possible folder and insert in stack, we will follow the split based on "/" so that we get folders
public String simplifyPath(String path) {
Stack<String> st= new Stack<>();
StringBuffer sb= new StringBuffer();
String paths[]=path.split("/");
for(int i=0;i<paths.length;i++){
String current=paths[i];
if(current.equals(""))
continue;
if( !current.equals(".") && !current.equals("..")){
st.push(current);
continue;
}
if(current.equals("..") && !st.isEmpty()){
st.pop();
}
}
if (st.empty()){
return "/";
}
String result="";
while(!st.empty()){
result = "/" + st.pop() + result;
}
return result;
}