From ef4e10d62121f4796bc720b7671b485de26aa76f Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Wed, 5 Nov 2025 22:56:08 +0900 Subject: [PATCH] =?UTF-8?q?[20251105]=20PGM=20/=20LV2=20/=20=EB=B0=A9?= =?UTF-8?q?=EB=AC=B8=20=EA=B8=B8=EC=9D=B4=20/=20=EC=9D=B4=EC=9D=B8?= =?UTF-8?q?=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\353\254\270 \352\270\270\354\235\264.md" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "LiiNi-coder/202511/05 PGM \353\260\251\353\254\270 \352\270\270\354\235\264.md" diff --git "a/LiiNi-coder/202511/05 PGM \353\260\251\353\254\270 \352\270\270\354\235\264.md" "b/LiiNi-coder/202511/05 PGM \353\260\251\353\254\270 \352\270\270\354\235\264.md" new file mode 100644 index 00000000..ca026e55 --- /dev/null +++ "b/LiiNi-coder/202511/05 PGM \353\260\251\353\254\270 \352\270\270\354\235\264.md" @@ -0,0 +1,61 @@ +```java +import java.util.*; + +class Solution { + static class Coords { + int x1, y1, x2, y2; + public Coords(int x1,int y1, int x2, int y2){ + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + } + @Override + public boolean equals(Object o){ + if(!(o instanceof Coords)) + return false; + Coords c = (Coords)o; + return (this.x1 == c.x1 && this.y1 == c.y1 && this.x2 == c.x2 && this.y2 == c.y2) || (this.x1 == c.x2 && this.y1 == c.y2 && this.x2 == c.x1 && this.y2 == c.y1); + } + + @Override + public int hashCode(){ + // 이렇게 순서를 맞춰줘야 함 + int sx1 = Math.min(x1, x2); + int sx2 = Math.max(x1, x2); + int sy1 = Math.min(y1, y2); + int sy2 = Math.max(y1, y2); + return Objects.hash(sx1, sy1, sx2, sy2); + // return Objects.hash(x1, x2, y1, y2); + } + } + + public int solution(String dirs) { + int answer = 0; + HashSet set = new HashSet<>(); + int x = 0; + int y = 0; + for(char d: dirs.toCharArray()){ + int nx = x; + int ny = y; + if(d == 'U') + ny++; + else if(d == 'D') + ny--; + else if(d == 'R') + nx++; + else if(d == 'L') + nx--; + + if(nx < -5 || nx > 5 || ny < -5 || ny > 5) + continue; + set.add(new Coords(x, y, nx, ny)); + x = nx; + y = ny; + } + answer = set.size(); + return answer; + } +} + +```