Max Area of Island
Last updated
Was this helpful?
Last updated
Was this helpful?
Given a non-empty 2D array grid
of 0's and 1's, an island is a group of 1
's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.
Find the maximum area of an island in the given 2D array. (If there is no island, the maximum area is 0.) ์ฃผ์ด์ง 2D ๋ฐฐ์ด์์ ์ต๋ ๋ฉด์ ์ธ ์ฌ์ ํฌ๊ธฐ๋ฅผ ๊ตฌํด๋ผ.//๋ฌธ์ ๋ฅผ ์ ํํ๊ฒ ์ดํดํ๋ ๊ฒ์ด ๊ฐ์ฅ ์ค์ํ๋ค!
์๊ณ ๋ฆฌ์ฆ 1.DFS/BFS๋ 4๋ฐฉ์ผ๋ก ์์นํ๋ค. 4๋ฒ์ ์ฌ๊ทํธ์ถ๋ณด๋ค๋, 4๋ฐฉ์ผ๋ก ๋๋ฆด ๋ ์/ํ/์ข/์ฐ ๋ฅผ ์๋ฏธํ๋ ์ขํ๊ฐ ๋ฐฐ์ด์ ๋ง๋ค์ด์ ๋๋ฆฐ๋ค. 2.DFS์ ๋ฉด์ ๊ฐ์ ๋ค๋ฃจ๋ ๋งค๊ฐ๋ณ์๋ฅผ ํ๋ ๋ ๋ฃ๋๋ค.