题目链接:https://leetcode.cn/problems/maximal-network-rank/
# 解题思路
# 提交结果
# 代码
| class Solution { |
| public int maximalNetworkRank(int n, int[][] roads) { |
| int[] edgeCnt = new int[n]; |
| boolean[][] connect = new boolean[n][n]; |
| |
| for (int[] r : roads) { |
| ++edgeCnt[r[0]]; |
| ++edgeCnt[r[1]]; |
| connect[r[0]][r[1]] = true; |
| } |
| |
| int maxCnt = 0; |
| for (int i = 0; i < n - 1; ++i) { |
| for (int j = i + 1; j < n; ++j) { |
| int cnt = (connect[i][j] || connect[j][i] ? -1 : 0) + edgeCnt[i] + edgeCnt[j]; |
| maxCnt = Math.max(maxCnt, cnt); |
| } |
| } |
| |
| return maxCnt; |
| } |
| } |