add new solutions
This commit is contained in:
parent
67cad91898
commit
81cc2d3ba6
19 changed files with 693 additions and 14 deletions
36
solutions/11/q1115/solution.go
Normal file
36
solutions/11/q1115/solution.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package q1115
|
||||
|
||||
type FooBar struct {
|
||||
n int
|
||||
foo, bar chan struct{}
|
||||
}
|
||||
|
||||
func NewFooBar(n int) *FooBar {
|
||||
ret := &FooBar{
|
||||
n: n,
|
||||
foo: make(chan struct{}, 1),
|
||||
bar: make(chan struct{}, 1),
|
||||
}
|
||||
ret.bar <- struct{}{}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (fb *FooBar) Foo(printFoo func()) {
|
||||
for i := 0; i < fb.n; i++ {
|
||||
<-fb.bar
|
||||
// printFoo() outputs "foo". Do not change or remove this line.
|
||||
printFoo()
|
||||
|
||||
fb.foo <- struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
func (fb *FooBar) Bar(printBar func()) {
|
||||
for i := 0; i < fb.n; i++ {
|
||||
<-fb.foo
|
||||
// printBar() outputs "bar". Do not change or remove this line.
|
||||
printBar()
|
||||
|
||||
fb.bar <- struct{}{}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue