Different output between OJ and local machine?


  • 0
    K

    For test cases ["xxx", "xox", "xxx"], my code output in OJ is different from my local machine in both visual studio in Windows and g++ 4.8.2 in Linux. My local result is right whereas OJ's is wrong.

    Here is my code:

    class Solution {
    public:
    bool helper(const int m, const int n, int x, int y, vector< std::vector<char> >& board) {
    	bool edge = (x == 0) || (x == m-1) || (y == 0) || (y == n-1);
    	if (edge && board[x][y] == 'o') return false;
    	if (board[x][y] == 'x') return true;
    	if (board[x][y] == '.') return true; // marked as visit
    	board[x][y] = '.';
    	bool res = helper(m, n, x-1, y, board) && helper(m, n, x+1, y, board) && helper(m, n, x, y-1, board) && helper(m, n, x, y+1, board);
    	if (res) board[x][y] = 'x';
    	else board[x][y] = '.';
    	return res;
    }
    
    void solve(vector< std::vector<char> >& board) {
    	int m = board.size();
    	if (m == 0) return;
    	int n = board[0].size();
    	int i, j;
    	for (i = 1; i < m-1; i++) {
    		for (j = 1; j < n-1; j++) {
    			if (board[i][j] == 'o') helper(m, n, i, j, board);
    		}
    	}
    	for (i = 0; i < m; i++) {
    		for (j = 0; j < n; j++) {
    			if (board[i][j] == '.') board[i][j] = 'o';
    		}
    	}
    }
    };

  • 0
    R

    Hi Kevin, I am also having the same issue as you. My code runs correctly on MSVC12 but gives incorrect result in the OJ. Maybe the mods can take a loo.


  • 1
    B

    I guess you have to use the format given by the problem. For example, it should be 'X'(uppercase) instead of 'x'.


  • 0
    K

    yes, I found that issue. Thank you!


Log in to reply
 

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