1 line
1.4 KiB
Plaintext
1 line
1.4 KiB
Plaintext
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Number of Provinces (547).ipynb","provenance":[],"authorship_tag":"ABX9TyPu1aY+cOeg5Poif8p8a8gH"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["# Problem 547. Number of Provinces\n","\n","There are n cities. Some of them are connected, while some are not. If city ais connected directly with city b, and city b is connected directly with city c, then city a is connected indirectly with city c.\n","A province is a group of directly or indirectly connected cities and no other cities outside of the group.\n","You are given an n x n matrix isConnected where isConnected[i][j] = 1 if the ith city and the jth city are directly connected, and isConnected[i][j] = 0 otherwise.\n","Return the total number of provinces.\n"," \n","Example 1:\n","\n","Input: isConnected = [[1,1,0],[1,1,0],[0,0,1]]\n","Output: 2\n","\n","Example 2:\n","\n","Input: isConnected = [[1,0,0],[0,1,0],[0,0,1]]\n","Output: 3\n","\n"," \n","Constraints:\n","1 <= n <= 200\n","n == isConnected.length\n","n == isConnected[i].length\n","isConnected[i][j] is 1 or 0.\n","isConnected[i][i] == 1\n","isConnected[i][j] == isConnected[j][i]\n"],"metadata":{"id":"_1UGGadq9wNI"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"xNWavXK-9pml"},"outputs":[],"source":[""]}]} |