天天看点

Leetcode: Word Search

Remember to change the character back after loop through all the possibility

非常聪明的方法1:O(1)空间的话可以不用visited数组,直接改board。改了之后,再访问的时候因为board[i][j] != word.charAt(ind)所以会return false

相同的思路,非常聪明方法2:用一个bit mask,After board[y][x] ^= 256 the char became not a valid letter. After second board[y][x] ^= 256

it became a valid letter again.