From f48d7209c795d13d9818d3cfc0779fd00ee589f5 Mon Sep 17 00:00:00 2001 From: Ilya Smyshlyaev Date: Fri, 16 Sep 2022 14:48:36 +0400 Subject: [PATCH] findunique added --- main.go | 12 ++++++++++++ rotation/rotation.go | 2 +- twonums/twonums.go | 4 ++-- unique/findunique.go | 11 +++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 main.go create mode 100644 unique/findunique.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..a190b89 --- /dev/null +++ b/main.go @@ -0,0 +1,12 @@ +package main + +import ( + "fmt" + "gotest/unique" +) + +func main() { + var nums = []int{2, 2, 4, 5, 4, 6, 6} + + fmt.Println(unique.FindUnique(nums)) +} diff --git a/rotation/rotation.go b/rotation/rotation.go index ffb285d..d10fcc1 100644 --- a/rotation/rotation.go +++ b/rotation/rotation.go @@ -3,7 +3,7 @@ package rotation func Rotation(A []int, K int) []int { for i := 0; i < K; i++ { - //A[len(A)-1: - последний элемент; A[:len(A)-1] - все элементы до последнего + //A[len(A)-1:] - последний элемент; A[:len(A)-1] - все элементы до последнего A = append(A[len(A)-1:], A[:len(A)-1]...) } diff --git a/twonums/twonums.go b/twonums/twonums.go index 19793f7..7401fa0 100644 --- a/twonums/twonums.go +++ b/twonums/twonums.go @@ -5,10 +5,10 @@ import "fmt" func main() { var test_nums []int test_nums = append(test_nums, 2, 3, 5, 6, 9, 1) - fmt.Print(twoSum(test_nums, 10)) + fmt.Print(TwoSum(test_nums, 10)) } -func twoSum(nums []int, target int) []int { +func TwoSum(nums []int, target int) []int { var result []int diff --git a/unique/findunique.go b/unique/findunique.go new file mode 100644 index 0000000..045935d --- /dev/null +++ b/unique/findunique.go @@ -0,0 +1,11 @@ +package unique + +func FindUnique(A []int) int { + var result int + + for i := 0; i < len(A); i++ { + result = result ^ A[i] + } + + return result +}