Finding all adjacent elements in a 2D array

后端 未结 5 1403
半阙折子戏
半阙折子戏 2021-02-15 18:07

I am working on a project where at one point I am stuck.

My question is for example I have the following 2D array containing 3 different integers.

2 2 2          


        
5条回答
  •  悲&欢浪女
    2021-02-15 19:08

    Suppose your matrix is a graph, and the elements are vertices. Two vertices are connected if they are adjacent and have the same value. If you perform any search in that graph, be it Breadth-First Search or Depth-First Search, you'll get exactly what you want. HTH

提交回复
热议问题