Skip to content

Add solution and test-cases for problem 1791 #918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions leetcode/1701-1800/1791.Find-Center-of-Star-Graph/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
# [1791.Find Center of Star Graph][title]

> [!WARNING|style:flat]
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)

## Description
There is an undirected **star** graph consisting of `n` nodes labeled from `1` to `n`. A star graph is a graph where there is one **center** node and **exactly** `n - 1` edges that connect the center node with every other node.

You are given a 2D integer array `edges` where each `edges[i] = [ui, vi]` indicates that there is an edge between the nodes `ui` and `vi`. Return the center of the given star graph.

**Example 1:**

**Example 1:**
![1](./star_graph.png)

```
Input: a = "11", b = "1"
Output: "100"
Input: edges = [[1,2],[2,3],[4,2]]
Output: 2
Explanation: As shown in the figure above, node 2 is connected to every other node, so 2 is the center.
```

## 题意
> ...
**Example 2:**

## 题解

### 思路1
> ...
Find Center of Star Graph
```go
```

Input: edges = [[1,2],[5,1],[1,3],[1,4]]
Output: 1
```

## 结语

Expand Down
11 changes: 9 additions & 2 deletions leetcode/1701-1800/1791.Find-Center-of-Star-Graph/Solution.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package Solution

func Solution(x bool) bool {
return x
func Solution(edges [][]int) int {
a, b := edges[0], edges[1]
if a[0] == b[1] || a[0] == b[0] {
return a[0]
}
if a[1] == b[1] || a[1] == b[0] {
return a[1]
}
return -1
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
inputs bool
expect bool
inputs [][]int
expect int
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", [][]int{{1, 2}, {2, 3}, {4, 2}}, 2},
{"TestCase2", [][]int{{1, 2}, {5, 1}, {1, 3}, {1, 4}}, 1},
}

// 开始测试
Expand All @@ -30,10 +29,10 @@ func TestSolution(t *testing.T) {
}
}

// 压力测试
// 压力测试
func BenchmarkSolution(b *testing.B) {
}

// 使用案列
// 使用案列
func ExampleSolution() {
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading