CPP solution


  • 0
    G

    class Solution {
    public:
    bool judgeCircle(string moves)
    {
    int count = 0;
    for (int i = 0; i < moves.size(); ++i)
    {
    switch (moves[i])
    {
    case 'r':
    ++count;
    break;
    case 'R':
    ++count;
    break;
    case 'l':
    --count;
    break;
    case 'L':
    --count;
    break;
    case 'u':
    ++count;
    break;
    case 'U':
    ++count;
    break;
    case 'd':
    --count;
    break;
    case 'D':
    --count;
    break;
    }

    }
    if (count == 0)
    
    	return true;
    
    else
    	return false;
    }
    

    };


Log in to reply
 

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