Why I got wrong answer?


  • 0
    H

    public class Solution {
    public void solve(char[][] board) {
    if (board.length < 3 || board[0].length < 3)
    {
    return;
    }
    boolean[][] flag= new boolean[board.length][board[0].length];

        for(int i=1;i<board.length-1;i++)
        {
            for(int j=1; j<board[0].length-1;j++)
            {
                if(board[i][j]=='o'&&board[i][j+1]=='x'&&board[i][j-1]=='x'&&board[i-1][j]=='x'&&board[i+1][j]=='x')
                {
                    flag[i][j]=true;
                }
            }
        }
         for(int i=1;i<board.length-1;i++)
        {
            for(int j=1; j<board[0].length-1;j++)
            {
                if(flag[i][j]) board[i][j]='x';
            }
        }
    }
    

    }

    Input ["xxx", "xox",“xxx”], and output is ["xxx", "xox", "xxx"]. But when I have my own test and take input as the one I provided above, I have the right output.
    Please let me know if I have any misunderstanding about this problem.


  • 2
    G

    Hey hughhao,

    The 'x' you are using is SMALL CASE . Where as the X they are sending is the "CAPITAL CASE"

    Check 'X' (capital X) and 'O' (capital O)

    Because of this your boolean flag is not even being filled up .

    Regards,
    Guru


Log in to reply
 

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