a easy solution


  • 0
    H

    int x = 0, y = 0;
    for (int i=0;i<moves .Length ;i++)
    {
    switch (moves[i])
    {
    case 'U':
    x++;
    break;
    case 'D':
    x--;
    break;
    case 'L':
    y--;
    break;
    case 'R':
    y++;
    break;
    default :
    return false ;
    break;
    }
    }
    if (x == 0 && y == 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.