diff --git a/Algorithm/Other/at coder/Other/A28/A28.js b/Algorithm/Other/at coder/Other/atcoder/A28/A28.js similarity index 100% rename from Algorithm/Other/at coder/Other/A28/A28.js rename to Algorithm/Other/at coder/Other/atcoder/A28/A28.js diff --git a/Algorithm/Other/at coder/Other/A36/A36.go b/Algorithm/Other/at coder/Other/atcoder/A36/A36.go similarity index 100% rename from Algorithm/Other/at coder/Other/A36/A36.go rename to Algorithm/Other/at coder/Other/atcoder/A36/A36.go diff --git a/Algorithm/Other/at coder/Other/A36/A36.java b/Algorithm/Other/at coder/Other/atcoder/A36/A36.java similarity index 100% rename from Algorithm/Other/at coder/Other/A36/A36.java rename to Algorithm/Other/at coder/Other/atcoder/A36/A36.java diff --git a/Algorithm/Other/at coder/Other/A36/A36.js b/Algorithm/Other/at coder/Other/atcoder/A36/A36.js similarity index 100% rename from Algorithm/Other/at coder/Other/A36/A36.js rename to Algorithm/Other/at coder/Other/atcoder/A36/A36.js diff --git a/Algorithm/Other/at coder/Other/A36/A36.php b/Algorithm/Other/at coder/Other/atcoder/A36/A36.php similarity index 100% rename from Algorithm/Other/at coder/Other/A36/A36.php rename to Algorithm/Other/at coder/Other/atcoder/A36/A36.php diff --git a/Algorithm/Other/at coder/Other/A36/A36.py b/Algorithm/Other/at coder/Other/atcoder/A36/A36.py similarity index 100% rename from Algorithm/Other/at coder/Other/A36/A36.py rename to Algorithm/Other/at coder/Other/atcoder/A36/A36.py diff --git a/Algorithm/Other/at coder/Other/A36/README.md b/Algorithm/Other/at coder/Other/atcoder/A36/README.md similarity index 100% rename from Algorithm/Other/at coder/Other/A36/README.md rename to Algorithm/Other/at coder/Other/atcoder/A36/README.md diff --git a/Algorithm/Other/at coder/Other/A37/A37.go b/Algorithm/Other/at coder/Other/atcoder/A37/A37.go similarity index 100% rename from Algorithm/Other/at coder/Other/A37/A37.go rename to Algorithm/Other/at coder/Other/atcoder/A37/A37.go diff --git a/Algorithm/Other/at coder/Other/A37/A37.js b/Algorithm/Other/at coder/Other/atcoder/A37/A37.js similarity index 100% rename from Algorithm/Other/at coder/Other/A37/A37.js rename to Algorithm/Other/at coder/Other/atcoder/A37/A37.js diff --git a/Algorithm/Other/at coder/Other/A37/A37.php b/Algorithm/Other/at coder/Other/atcoder/A37/A37.php similarity index 100% rename from Algorithm/Other/at coder/Other/A37/A37.php rename to Algorithm/Other/at coder/Other/atcoder/A37/A37.php diff --git a/Algorithm/Other/at coder/Other/A37/A37.py b/Algorithm/Other/at coder/Other/atcoder/A37/A37.py similarity index 100% rename from Algorithm/Other/at coder/Other/A37/A37.py rename to Algorithm/Other/at coder/Other/atcoder/A37/A37.py diff --git a/Algorithm/Other/at coder/Other/A37/README.md b/Algorithm/Other/at coder/Other/atcoder/A37/README.md similarity index 100% rename from Algorithm/Other/at coder/Other/A37/README.md rename to Algorithm/Other/at coder/Other/atcoder/A37/README.md diff --git a/Algorithm/Other/at coder/Other/A38/A38.go b/Algorithm/Other/at coder/Other/atcoder/A38/A38.go similarity index 100% rename from Algorithm/Other/at coder/Other/A38/A38.go rename to Algorithm/Other/at coder/Other/atcoder/A38/A38.go diff --git a/Algorithm/Other/at coder/Other/A38/A38.java b/Algorithm/Other/at coder/Other/atcoder/A38/A38.java similarity index 100% rename from Algorithm/Other/at coder/Other/A38/A38.java rename to Algorithm/Other/at coder/Other/atcoder/A38/A38.java diff --git a/Algorithm/Other/at coder/Other/A38/A38.js b/Algorithm/Other/at coder/Other/atcoder/A38/A38.js similarity index 100% rename from Algorithm/Other/at coder/Other/A38/A38.js rename to Algorithm/Other/at coder/Other/atcoder/A38/A38.js diff --git a/Algorithm/Other/at coder/Other/A38/A38.php b/Algorithm/Other/at coder/Other/atcoder/A38/A38.php similarity index 100% rename from Algorithm/Other/at coder/Other/A38/A38.php rename to Algorithm/Other/at coder/Other/atcoder/A38/A38.php diff --git a/Algorithm/Other/at coder/Other/A38/A38.py b/Algorithm/Other/at coder/Other/atcoder/A38/A38.py similarity index 100% rename from Algorithm/Other/at coder/Other/A38/A38.py rename to Algorithm/Other/at coder/Other/atcoder/A38/A38.py diff --git a/Algorithm/Other/at coder/Other/A38/README.md b/Algorithm/Other/at coder/Other/atcoder/A38/README.md similarity index 100% rename from Algorithm/Other/at coder/Other/A38/README.md rename to Algorithm/Other/at coder/Other/atcoder/A38/README.md diff --git a/Algorithm/Other/at coder/Other/A40/A40.go b/Algorithm/Other/at coder/Other/atcoder/A40/A40.go similarity index 100% rename from Algorithm/Other/at coder/Other/A40/A40.go rename to Algorithm/Other/at coder/Other/atcoder/A40/A40.go diff --git a/Algorithm/Other/at coder/Other/A40/A40.java b/Algorithm/Other/at coder/Other/atcoder/A40/A40.java similarity index 100% rename from Algorithm/Other/at coder/Other/A40/A40.java rename to Algorithm/Other/at coder/Other/atcoder/A40/A40.java diff --git a/Algorithm/Other/at coder/Other/A40/A40.js b/Algorithm/Other/at coder/Other/atcoder/A40/A40.js similarity index 100% rename from Algorithm/Other/at coder/Other/A40/A40.js rename to Algorithm/Other/at coder/Other/atcoder/A40/A40.js diff --git a/Algorithm/Other/at coder/Other/A40/A40.php b/Algorithm/Other/at coder/Other/atcoder/A40/A40.php similarity index 100% rename from Algorithm/Other/at coder/Other/A40/A40.php rename to Algorithm/Other/at coder/Other/atcoder/A40/A40.php diff --git a/Algorithm/Other/at coder/Other/A40/A40.py b/Algorithm/Other/at coder/Other/atcoder/A40/A40.py similarity index 100% rename from Algorithm/Other/at coder/Other/A40/A40.py rename to Algorithm/Other/at coder/Other/atcoder/A40/A40.py diff --git a/Algorithm/Other/at coder/Other/A40/README.md b/Algorithm/Other/at coder/Other/atcoder/A40/README.md similarity index 100% rename from Algorithm/Other/at coder/Other/A40/README.md rename to Algorithm/Other/at coder/Other/atcoder/A40/README.md diff --git a/Algorithm/Other/at coder/Other/A41/A41.js b/Algorithm/Other/at coder/Other/atcoder/A41/A41.js similarity index 100% rename from Algorithm/Other/at coder/Other/A41/A41.js rename to Algorithm/Other/at coder/Other/atcoder/A41/A41.js diff --git a/Algorithm/Other/at coder/Other/A41/A41.php b/Algorithm/Other/at coder/Other/atcoder/A41/A41.php similarity index 100% rename from Algorithm/Other/at coder/Other/A41/A41.php rename to Algorithm/Other/at coder/Other/atcoder/A41/A41.php diff --git a/Algorithm/Other/at coder/Other/A41/README.md b/Algorithm/Other/at coder/Other/atcoder/A41/README.md similarity index 100% rename from Algorithm/Other/at coder/Other/A41/README.md rename to Algorithm/Other/at coder/Other/atcoder/A41/README.md diff --git a/Algorithm/Other/at coder/Other/A42/A42.go b/Algorithm/Other/at coder/Other/atcoder/A42/A42.go similarity index 100% rename from Algorithm/Other/at coder/Other/A42/A42.go rename to Algorithm/Other/at coder/Other/atcoder/A42/A42.go diff --git a/Algorithm/Other/at coder/Other/A42/A42.java b/Algorithm/Other/at coder/Other/atcoder/A42/A42.java similarity index 100% rename from Algorithm/Other/at coder/Other/A42/A42.java rename to Algorithm/Other/at coder/Other/atcoder/A42/A42.java diff --git a/Algorithm/Other/at coder/Other/A42/A42.js b/Algorithm/Other/at coder/Other/atcoder/A42/A42.js similarity index 100% rename from Algorithm/Other/at coder/Other/A42/A42.js rename to Algorithm/Other/at coder/Other/atcoder/A42/A42.js diff --git a/Algorithm/Other/at coder/Other/A42/A42.php b/Algorithm/Other/at coder/Other/atcoder/A42/A42.php similarity index 100% rename from Algorithm/Other/at coder/Other/A42/A42.php rename to Algorithm/Other/at coder/Other/atcoder/A42/A42.php diff --git a/Algorithm/Other/at coder/Other/A42/A42.py b/Algorithm/Other/at coder/Other/atcoder/A42/A42.py similarity index 100% rename from Algorithm/Other/at coder/Other/A42/A42.py rename to Algorithm/Other/at coder/Other/atcoder/A42/A42.py diff --git a/Algorithm/Other/at coder/Other/A42/README.md b/Algorithm/Other/at coder/Other/atcoder/A42/README.md similarity index 100% rename from Algorithm/Other/at coder/Other/A42/README.md rename to Algorithm/Other/at coder/Other/atcoder/A42/README.md diff --git a/Algorithm/Other/at coder/Other/A43/A43.go b/Algorithm/Other/at coder/Other/atcoder/A43/A43.go similarity index 100% rename from Algorithm/Other/at coder/Other/A43/A43.go rename to Algorithm/Other/at coder/Other/atcoder/A43/A43.go diff --git a/Algorithm/Other/at coder/Other/A43/A43.java b/Algorithm/Other/at coder/Other/atcoder/A43/A43.java similarity index 100% rename from Algorithm/Other/at coder/Other/A43/A43.java rename to Algorithm/Other/at coder/Other/atcoder/A43/A43.java diff --git a/Algorithm/Other/at coder/Other/A43/A43.js b/Algorithm/Other/at coder/Other/atcoder/A43/A43.js similarity index 100% rename from Algorithm/Other/at coder/Other/A43/A43.js rename to Algorithm/Other/at coder/Other/atcoder/A43/A43.js diff --git a/Algorithm/Other/at coder/Other/A43/A43.php b/Algorithm/Other/at coder/Other/atcoder/A43/A43.php similarity index 100% rename from Algorithm/Other/at coder/Other/A43/A43.php rename to Algorithm/Other/at coder/Other/atcoder/A43/A43.php diff --git a/Algorithm/Other/at coder/Other/A43/A43.py b/Algorithm/Other/at coder/Other/atcoder/A43/A43.py similarity index 100% rename from Algorithm/Other/at coder/Other/A43/A43.py rename to Algorithm/Other/at coder/Other/atcoder/A43/A43.py diff --git a/Algorithm/Other/at coder/Other/A43/README.md b/Algorithm/Other/at coder/Other/atcoder/A43/README.md similarity index 100% rename from Algorithm/Other/at coder/Other/A43/README.md rename to Algorithm/Other/at coder/Other/atcoder/A43/README.md diff --git a/Algorithm/Other/at coder/Other/A44/A44-1.js b/Algorithm/Other/at coder/Other/atcoder/A44/A44-1.js similarity index 100% rename from Algorithm/Other/at coder/Other/A44/A44-1.js rename to Algorithm/Other/at coder/Other/atcoder/A44/A44-1.js diff --git a/Algorithm/Other/at coder/Other/A44/A44-2.js b/Algorithm/Other/at coder/Other/atcoder/A44/A44-2.js similarity index 100% rename from Algorithm/Other/at coder/Other/A44/A44-2.js rename to Algorithm/Other/at coder/Other/atcoder/A44/A44-2.js diff --git a/Algorithm/Other/at coder/Other/A44/A44.go b/Algorithm/Other/at coder/Other/atcoder/A44/A44.go similarity index 100% rename from Algorithm/Other/at coder/Other/A44/A44.go rename to Algorithm/Other/at coder/Other/atcoder/A44/A44.go diff --git a/Algorithm/Other/at coder/Other/A44/A44.java b/Algorithm/Other/at coder/Other/atcoder/A44/A44.java similarity index 100% rename from Algorithm/Other/at coder/Other/A44/A44.java rename to Algorithm/Other/at coder/Other/atcoder/A44/A44.java diff --git a/Algorithm/Other/at coder/Other/A44/A44.php b/Algorithm/Other/at coder/Other/atcoder/A44/A44.php similarity index 100% rename from Algorithm/Other/at coder/Other/A44/A44.php rename to Algorithm/Other/at coder/Other/atcoder/A44/A44.php diff --git a/Algorithm/Other/at coder/Other/A44/A44.py b/Algorithm/Other/at coder/Other/atcoder/A44/A44.py similarity index 100% rename from Algorithm/Other/at coder/Other/A44/A44.py rename to Algorithm/Other/at coder/Other/atcoder/A44/A44.py diff --git a/Algorithm/Other/at coder/Other/A44/README.md b/Algorithm/Other/at coder/Other/atcoder/A44/README.md similarity index 100% rename from Algorithm/Other/at coder/Other/A44/README.md rename to Algorithm/Other/at coder/Other/atcoder/A44/README.md diff --git a/Algorithm/Other/at coder/Other/A45/A45.js b/Algorithm/Other/at coder/Other/atcoder/A45/A45.js similarity index 100% rename from Algorithm/Other/at coder/Other/A45/A45.js rename to Algorithm/Other/at coder/Other/atcoder/A45/A45.js diff --git a/Algorithm/Other/at coder/Other/A45/A45.py b/Algorithm/Other/at coder/Other/atcoder/A45/A45.py similarity index 100% rename from Algorithm/Other/at coder/Other/A45/A45.py rename to Algorithm/Other/at coder/Other/atcoder/A45/A45.py diff --git a/Algorithm/Other/at coder/Other/A45/A45.ts b/Algorithm/Other/at coder/Other/atcoder/A45/A45.ts similarity index 100% rename from Algorithm/Other/at coder/Other/A45/A45.ts rename to Algorithm/Other/at coder/Other/atcoder/A45/A45.ts diff --git a/Algorithm/Other/at coder/Other/A45/README.md b/Algorithm/Other/at coder/Other/atcoder/A45/README.md similarity index 100% rename from Algorithm/Other/at coder/Other/A45/README.md rename to Algorithm/Other/at coder/Other/atcoder/A45/README.md diff --git a/Algorithm/Other/at coder/Other/leetcode/6. Zigzag Conversion/README.md b/Algorithm/Other/at coder/Other/leetcode/6. Zigzag Conversion/README.md new file mode 100644 index 00000000..471e793c --- /dev/null +++ b/Algorithm/Other/at coder/Other/leetcode/6. Zigzag Conversion/README.md @@ -0,0 +1,82 @@ + +```ts +function convert(s: string, numRows: number): string { + if (numRows === 1 || s.length <= numRows) return s; + + const rows: string[] = Array(Math.min(numRows, s.length)).fill(""); + let currentRow = 0; + let goingDown = false; + + for (const char of s) { + rows[currentRow] += char; + + // 一番上または一番下に到達したら方向を反転 + if (currentRow === 0 || currentRow === numRows - 1) { + goingDown = !goingDown; + } + + currentRow += goingDown ? 1 : -1; + } + + return rows.join(""); +} +``` + +--- + +### 🔍 実行例: + +#### 入力1: + +```ts +console.log(convert("PAYPALISHIRING", 3)); +``` + +出力: + +``` +"PAHNAPLSIIGYIR" +``` + +#### 入力2: + +```ts +console.log(convert("PAYPALISHIRING", 4)); +``` + +出力: + +``` +"PINALSIGYAHRPI" +``` + +#### 入力3: + +```ts +console.log(convert("A", 1)); +``` + +出力: + +``` +"A" +``` + +--- + +### 🧠 アルゴリズムの考え方(図付き) + +例: `s = "PAYPALISHIRING", numRows = 4` + +``` +P I N +A L S I G +Y A H R +P I +``` + +* 各文字を1文字ずつ `rows[]` に追加 +* 上から下に移動し、最下段に達したら反転して上に戻るというパターン +* 方向はフラグ `goingDown` で管理 + +--- \ No newline at end of file diff --git a/Algorithm/Other/at coder/Other/leetcode/6. Zigzag Conversion/ZigzagConversion.ts b/Algorithm/Other/at coder/Other/leetcode/6. Zigzag Conversion/ZigzagConversion.ts new file mode 100644 index 00000000..69ceba7d --- /dev/null +++ b/Algorithm/Other/at coder/Other/leetcode/6. Zigzag Conversion/ZigzagConversion.ts @@ -0,0 +1,20 @@ +function convert(s: string, numRows: number): string { + if (numRows === 1 || s.length <= numRows) return s; + + const rows: string[] = Array(Math.min(numRows, s.length)).fill(''); + let currentRow = 0; + let goingDown = false; + + for (const char of s) { + rows[currentRow] += char; + + // 一番上または一番下に到達したら方向を反転 + if (currentRow === 0 || currentRow === numRows - 1) { + goingDown = !goingDown; + } + + currentRow += goingDown ? 1 : -1; + } + + return rows.join(''); +}