瀏覽代碼

Added sorting

Piotr Czajkowski 1 年之前
父節點
當前提交
0368a2487f
共有 1 個文件被更改,包括 9 次插入0 次删除
  1. 9 0
      18/code.go

+ 9 - 0
18/code.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"log"
 	"os"
+	"sort"
 	"strings"
 )
 
@@ -76,6 +77,14 @@ func plot(plan []Dig) []Point {
 		result = append(result, current.getPoints(plan[i])...)
 	}
 
+	sort.Slice(result, func(i, j int) bool {
+		if result[i].y == result[j].y {
+			return result[i].x < result[j].x
+		}
+
+		return result[i].y < result[j].y
+	})
+
 	return result
 }