Something wrong in the testcase or my code


  • 0
    U

    Run code status shows that when the input is "UD", my output is "false". But actually I run my code on my computer and the output is "true". It is very strange. Could you help me find out the reason why it happens please?

    class Solution {
    public:
        bool judgeCircle(string moves) {
            int u, d, l, r;
    	u = 0;
            d = 0;
            l = 0;
            r = 0;
    
    	    int i = 1;
    	    while (moves[i] != '"')
    	    {
    		    if (moves[i] == 'U')
    			    u++;
    		    else if (moves[i] == 'D')
    			    d++;
    		    else if (moves[i] == 'L')
    			    l++;
    		    else if (moves[i] == 'R')
    			    r++;
    
    		    i++;
    	    }
    
    	    if ((u == d) && (l == r))
    		    return true;
    	    else
    		    return false;
        }
    };
    

  • 0

    It's your code that's bad. Hint: You already start wrong, ignoring the first character of the string.


  • 0
    U

    @ManuelP Thank you very much for your help. I find out it is because I thought the first character was a part of input. But in fact it isn't. Thank you for your kind help.


Log in to reply
 

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