From 066d227105cd7f93f646ce53388f44f4a1830aff Mon Sep 17 00:00:00 2001 From: "Joon Yeol, Lee" Date: Mon, 19 May 2025 10:28:12 +0900 Subject: [PATCH] =?UTF-8?q?[=EC=9D=B4=EC=A4=80=EC=97=B4]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../892.cpp" | 38 ++++++++++++++ .../117.cpp" | 49 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 "leetcode2/1easy/\354\235\264\354\244\200\354\227\264/892.cpp" create mode 100644 "leetcode2/2medium/\354\235\264\354\244\200\354\227\264/117.cpp" diff --git "a/leetcode2/1easy/\354\235\264\354\244\200\354\227\264/892.cpp" "b/leetcode2/1easy/\354\235\264\354\244\200\354\227\264/892.cpp" new file mode 100644 index 00000000..2a5e4bcc --- /dev/null +++ "b/leetcode2/1easy/\354\235\264\354\244\200\354\227\264/892.cpp" @@ -0,0 +1,38 @@ +class Solution { +public: + int surfaceArea(vector>& grid) { + int output = 0; + int dy[4] = {1, 0, -1, 0}; + int dx[4] = {0, 1, 0, -1}; + int nSize = grid.size(); + + for (int i = 0; i < nSize; i++) + { + for (int j = 0; j < nSize; j++) + { + for (int m = 1; m <= grid[i][j]; m++) + { + int adj = 0; + for (int u = 0; u < 4; u++) + { + int tmpY = i + dy[u]; + int tmpX = j + dx[u]; + if (tmpY < 0 || tmpY >= nSize || tmpX < 0 || tmpX >= nSize) + continue; + if (grid[tmpY][tmpX] >= m) // 1d adj + adj++; + } + if (grid[i][j] > 1) + { + if (m == 1 || m == grid[i][j]) + adj++; + else if (m != 1 && m != grid[i][j]) + adj += 2; + } + output += 6 - adj; + } + } + } + return output; + } +}; \ No newline at end of file diff --git "a/leetcode2/2medium/\354\235\264\354\244\200\354\227\264/117.cpp" "b/leetcode2/2medium/\354\235\264\354\244\200\354\227\264/117.cpp" new file mode 100644 index 00000000..0eeb2525 --- /dev/null +++ "b/leetcode2/2medium/\354\235\264\354\244\200\354\227\264/117.cpp" @@ -0,0 +1,49 @@ +/* +// Definition for a Node. +class Node { +public: + int val; + Node* left; + Node* right; + Node* next; + + Node() : val(0), left(NULL), right(NULL), next(NULL) {} + + Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {} + + Node(int _val, Node* _left, Node* _right, Node* _next) + : val(_val), left(_left), right(_right), next(_next) {} +}; +*/ + +class Solution { +public: + Node* connect(Node* root) { + if (!root) return nullptr; + + queue q; + q.push(root); + + while (!q.empty()) + { + int size = q.size(); + Node* prev = nullptr; + + for (int i = 0; i < size; i++) + { + Node* curr = q.front(); + q.pop(); + + if (prev) + prev->next = curr; + + prev = curr; + + if (curr->left) q.push(curr->left); + if (curr->right) q.push(curr->right); + } + prev->next = nullptr; + } + return root; + } +}; \ No newline at end of file