Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
✨ Added solution to 1431
  • Loading branch information
Sathish Babu committed May 23, 2020
commit bfdcf6156d6c1a2040b96d71575d365263202991
32 changes: 32 additions & 0 deletions src/1431.Kids-With-the-Greatest-Number-of-Candies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# [1363.Largest Multiple of Three][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-leetcode)

## Description

**Example 1:**

```
Input: candies=[2,3,5,1,3], extraCandies=3
Output: [true,true,true,false,true]
```

## 题意
> ...

## 题解

### 思路1
> ...
Largest Multiple of Three
```go
```


## 结语

如果你同我一样热爱数据结构、算法、LeetCode,可以关注我 GitHub 上的 LeetCode 题解:[awesome-golang-leetcode][me]

[title]: https://leetcode.com/problems/largest-multiple-of-three/
[me]: https://github.com/kylesliu/awesome-golang-leetcode
19 changes: 19 additions & 0 deletions src/1431.Kids-With-the-Greatest-Number-of-Candies/Solution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package Solution

func Solution(candies []int, extraCandies int) []bool {
max := candies[0]
for i := 1; i < len(candies); i++ {
if candies[i] > max {
max = candies[i]
}
}
res := make([]bool, 0)
for i := 0; i < len(candies); i++ {
if candies[i]+extraCandies >= max {
res = append(res, true)
} else {
res = append(res, false)
}
}
return res
}
42 changes: 42 additions & 0 deletions src/1431.Kids-With-the-Greatest-Number-of-Candies/Solution_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package Solution

import (
"reflect"
"strconv"
"testing"
)

func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
candies []int
extraCandies int
expect []bool
}{
{"TestCase", []int{2, 3, 5, 1, 3}, 3, []bool{true, true, true, false, true}},
{"TestCase", []int{10, 100}, 50, []bool{false, true}},
{"TestCase", []int{1, 1}, 1, []bool{true, true}},
}

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

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

}

// 使用案列
func ExampleSolution() {

}