Skip to content
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
Binary file added leetcode/701-800/0764.Largest-Plus-Sign/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added leetcode/701-800/0764.Largest-Plus-Sign/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 17 additions & 14 deletions leetcode/701-800/0764.Largest-Plus-Sign/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
# [764.Largest Plus Sign][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
You are given an integer `n`. You have an `n x n` binary `grid` grid with all values initially `1`'s except for some indices given in the array `mines`. The `ith` element of the array `mines` is defined as `mines[i] = [xi, yi]` where `grid[xi][yi] == 0`.

Return the order of the largest **axis-aligned** plus sign of 1's contained in `grid`. If there is none, return `0`.

An **axis-aligned** plus sign of `1`'s of order `k` has some center `grid[r][c] == 1` along with four arms of length `k - 1` going up, down, left, and right, and made of `1`'s. Note that there could be `0`'s or `1`'s beyond the arms of the plus sign, only the relevant area of the plus sign is checked for `1`'s.

**Example 1:**
**Example 1:**

![1](./1.jpg)

```
Input: a = "11", b = "1"
Output: "100"
Input: n = 5, mines = [[4,2]]
Output: 2
Explanation: In the above grid, the largest plus sign can only be of order 2. One of them is shown.
```

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

## 题解
![2](./2.jpg)

### 思路1
> ...
Largest Plus Sign
```go
```

Input: n = 1, mines = [[0,0]]
Output: 0
Explanation: There is no plus sign, so return 0.
```

## 结语

Expand Down
81 changes: 79 additions & 2 deletions leetcode/701-800/0764.Largest-Plus-Sign/Solution.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,82 @@
package Solution

func Solution(x bool) bool {
return x
type l764 struct {
up, down, left, right int
}

func Solution(n int, mines [][]int) int {
var ans int
checker := make(map[int]map[int]struct{})
for _, m := range mines {
if _, ok := checker[m[0]]; !ok {
checker[m[0]] = map[int]struct{}{}
}
checker[m[0]][m[1]] = struct{}{}
}
order := make([][]l764, n)
for i := range n {
order[i] = make([]l764, n)
}

for i := 0; i < n; i++ {
one := 0
for j := 0; j < n; j++ {
if v, ok := checker[i]; ok {
if _, ok1 := v[j]; ok1 {
one = 0
continue
}
}
order[i][j].left = one
one++
}
one = 0
for j := n - 1; j >= 0; j-- {
if v, ok := checker[i]; ok {
if _, ok1 := v[j]; ok1 {
one = 0
continue
}
}
order[i][j].right = one
one++

}

one = 0
for j := 0; j < n; j++ {
if v, ok := checker[j]; ok {
if _, ok1 := v[i]; ok1 {
one = 0
continue
}
}
order[j][i].up = one
one++
}
one = 0
for j := n - 1; j >= 0; j-- {
if v, ok := checker[j]; ok {
if _, ok1 := v[i]; ok1 {
one = 0
continue
}
}
order[j][i].down = one
one++
}
}

for i := 0; i < n; i++ {
for j := 0; j < n; j++ {
if v, ok := checker[i]; ok {
if _, ok1 := v[j]; ok1 {
continue
}
}

ans = max(ans, min(order[i][j].down, order[i][j].up, order[i][j].left, order[i][j].right)+1)
}
}
return ans
}
20 changes: 10 additions & 10 deletions leetcode/701-800/0764.Largest-Plus-Sign/Solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
inputs bool
expect bool
n int
mines [][]int
expect int
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", 5, [][]int{{4, 2}}, 2},
{"TestCase2", 1, [][]int{{0, 0}}, 0},
}

// 开始测试
for i, c := range cases {
t.Run(c.name+" "+strconv.Itoa(i), func(t *testing.T) {
got := Solution(c.inputs)
got := Solution(c.n, c.mines)
if !reflect.DeepEqual(got, c.expect) {
t.Fatalf("expected: %v, but got: %v, with inputs: %v",
c.expect, got, c.inputs)
t.Fatalf("expected: %v, but got: %v, with inputs: %v %v",
c.expect, got, c.n, c.mines)
}
})
}
}

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

// 使用案列
// 使用案列
func ExampleSolution() {
}
Loading