/SwiftAlgorithms

Primary LanguageSwiftMIT LicenseMIT

SwiftAlgorithms

Personal Study of solving algorithm problems using Swift

Count of two

Find the number of number two from 0 to N

Example: for 25, output is 9

(02, 12, 20, 21, 22, 23, 24, 25)

Solution

Pond size

The integer matrix representing a plot of land and water. Values of 0 represents water, while numbers > 0 represent land. A pond is a region of water connected vertically, horizontally or diagonally. The size of the pond is the number of connected water cells.

Compute the sizes of all ponts in the matrix.

Ex:

0	2	1	0
0	1	0	1
1	1	0	1
0	1	0	1

Output: 2, 4, 1 (in any order)

Solution