LeetCode-Solutions
LeetCode-Solutions copied to clipboard
Create Car-Fleet-II.java
Pull Request Template
Description
This PR adds a solution for the problem "419. Battleships in a Board" from LeetCode.
The goal is to count the number of battleships present on a given 2D board without modifying the board or using extra space.
Approach:
We iterate through each cell in the board. For a cell containing 'X', we check if it is the top-left-most part of a new battleship by ensuring there's no 'X' directly above or to the left. If these conditions hold, we increment the battleship count.
Dependencies:
No external dependencies are required for this change.
Put check marks:
Have you made changes in README file?
- [x] Added problem & solution under correct topic.
- [x] Specified Space & Time complexity.
- [x] Specified difficulty level, tag & Note(if any).
How Has This Been Tested?
The solution has been tested using a sample input and produces the correct number of battleships.
- [x] Test A: Sample board with two battleships
- [ ] Test B
Make sure all below guidelines are followed else PR will get Rejected:
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code so that it is easy to understand
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] Any dependent changes have been merged and published in downstream modules