-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #597 from 0xff-dev/1615
Add solution and test-cases for problem 1615
- Loading branch information
Showing
5 changed files
with
71 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,31 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
func Solution(n int, roads [][]int) int { | ||
adj := make([][]bool, n) | ||
for i := 0; i < n; i++ { | ||
adj[i] = make([]bool, n) | ||
} | ||
count := make([]int, n) | ||
for _, road := range roads { | ||
from, to := road[0], road[1] | ||
adj[from][to] = true | ||
adj[to][from] = true | ||
count[from]++ | ||
count[to]++ | ||
} | ||
ans := 0 | ||
|
||
for c1 := 0; c1 < n-1; c1++ { | ||
for c2 := c1 + 1; c2 < n; c2++ { | ||
r := count[c1] + count[c2] | ||
if adj[c1][c2] { | ||
r-- | ||
} | ||
if r > ans { | ||
ans = r | ||
} | ||
} | ||
} | ||
|
||
return ans | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.