Thursday, August 17, 2017

[Leetcode]Number of Islands

LC link
Summary:
Ignore boundaries, sink method handles all logic and sink up/down left/right
1. Line 14, old drill, when I wrote line 14, i and j could not be negative, but in line 17,18, we access i - 1, j - 1, we need to check whether i and j are negative. Always check validness of objects or index.
 Test case ["1011011"]
2. Line 17, 18 Whenever create or change method signature, check signatures!
3.

# 000
# 010
# 000 is a valid island

4.  0 == '0' returns False

5. Line 14, 17, 18 our approach ignores values on edges. So we need to sink up, down, left ,right whenever we find a island
["111","010","111"]  for example, case like that

6. let sink method takes care of input check and most of logics

No comments:

Post a Comment