From e84dda0dee96e9491d2436a1a52225db8cfef232 Mon Sep 17 00:00:00 2001 From: VicRen Date: Thu, 17 Dec 2020 08:59:15 +0800 Subject: [PATCH] 20201217 --- 20201217/main.go | 22 ++++++++++++++++++++++ 20201217/main_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 20201217/main.go create mode 100644 20201217/main_test.go diff --git a/20201217/main.go b/20201217/main.go new file mode 100644 index 0000000..15491c1 --- /dev/null +++ b/20201217/main.go @@ -0,0 +1,22 @@ +package main + +import ( + "sort" +) + +func main() { + +} + +func process(g, s []int) int { + sort.Ints(g) + sort.Ints(s) + i, j := 0, 0 + for i < len(g) && j < len(s) { + if s[j] >= g[i] { + i++ + } + j++ + } + return i +} diff --git a/20201217/main_test.go b/20201217/main_test.go new file mode 100644 index 0000000..b381df9 --- /dev/null +++ b/20201217/main_test.go @@ -0,0 +1,39 @@ +package main + +import "testing" + +func Test_process(t *testing.T) { + type args struct { + g []int + s []int + } + tests := []struct { + name string + args args + want int + }{ + { + "test1", + args{ + g: []int{1, 2, 3}, + s: []int{1, 1}, + }, + 1, + }, + { + "test2", + args{ + g: []int{1, 2}, + s: []int{1, 2, 3}, + }, + 2, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := process(tt.args.g, tt.args.s); got != tt.want { + t.Errorf("process() = %v, want %v", got, tt.want) + } + }) + } +}