Example 1
Input
len int has int 2 has int 9
Expected output
3 true false
Example 2
Input
add str go add str go len str has str go has str rust
Expected output
1 true false
1 hidden test · Limit 2 s · 256 MB
Cài đặt kiểu tập hợp generic:
type Set[T comparable] struct { /* ... */ }
func NewSet[T comparable](items ...T) *Set[T]
func (s *Set[T]) Add(v T)
func (s *Set[T]) Has(v T) bool
func (s *Set[T]) Len() intDriver tạo NewSet(1, 2, 2, 3) (một Set[int] có 3 phần tử) và NewSet[string](), rồi chạy các lệnh add, has, len trên từng tập.
NOTE
Bạn chỉ viết phần code trong khung soạn thảo — package main, hàm main đọc input/in kết quả đã có sẵn. Các package đã import: fmt. Không thêm import khác.
type Set[T comparable] struct {
// TODO
}
func NewSet[T comparable](items ...T) *Set[T] {
// TODO
return &Set[T]{}
}
func (s *Set[T]) Add(v T) {}
func (s *Set[T]) Has(v T) bool { return false }
func (s *Set[T]) Len() int { return 0 }
Comments