Is there any problem with OJ? A weird result


  • 0
    R

    I got a weird result. And I can got the expected result "/..." on my pc.

    Input:	"/..."
    Output:	...
    Expected:	"/..."
    

    The following is the codes.

    public String simplifyPath(String path) {
            int pointer = -1;
        	String[] mystack = new String[100];
        	String[] paths = path.split("/");
        	
        	for(int i = 0; i < paths.length; i++)
        	{
        		String cs = paths[i];
        		if(cs == null || cs.equals(".") || cs.length() == 0)
        			continue;
        		if(cs.equals(".."))
        		{
        		    if(pointer > -1)
        			    pointer -= 1;
        		}
        		else
        		{
        			pointer += 1;
        			mystack[pointer] = cs;
        		}
        	}
        	if (pointer < 0)
        		return "/";
        		
        	String result = "";
        	while(pointer > -1)
        	{
        		System.out.println(mystack[pointer]);
        		result = "/" + mystack[pointer] + result;
        		pointer -= 1;
        	}
            return result;  
        }

  • 0
    R

    I found my fault. Need to delete debug code.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.