Search
⌘K

Leetcode 419. Battleships in a Board

Count how many non-adjacent battleships (each a straight 1×k or k×1 segment) appear in an m×n grid of 'X' and '.' cells. Because ships never touch, you can scan the board once and identify each ship by its starting cell (no 'X' above or to the left), achieving one-pass O(1) extra space.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.