From 722dc1485482b35f5680db6a750e189039ab594f Mon Sep 17 00:00:00 2001 From: "junfeng.fj" Date: 2021年1月24日 13:40:13 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0lcof-cpp=E7=89=88?= =?UTF-8?q?=E6=9C=AC[=E6=9C=BA=E5=99=A8=E4=BA=BA=E7=9A=84=E8=BF=90?= =?UTF-8?q?=E5=8A=A8=E8=8C=83=E5=9B=B4]=E9=A2=98=E8=A7=A3=E6=80=9D?= =?UTF-8?q?=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../README.md" | 46 +++++++++++++++++++ .../Solution.cpp" | 0 2 files changed, 46 insertions(+) create mode 100644 "lcof/351円235円242円350円257円225円351円242円23013円. 346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円/Solution.cpp" diff --git "a/lcof/351円235円242円350円257円225円351円242円23013円. 346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円/README.md" "b/lcof/351円235円242円350円257円225円351円242円23013円. 346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円/README.md" index c6bfbe8dcd0a8..160778737cbf1 100644 --- "a/lcof/351円235円242円350円257円225円351円242円23013円. 346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円/README.md" +++ "b/lcof/351円235円242円350円257円225円351円242円23013円. 346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円/README.md" @@ -173,6 +173,52 @@ func dfs(x, y, m, n, k int, visited [][]bool) int { } ``` +```cpp +class Solution { +public: + int checksum(int m, int n, int target) { + int a = 0; + while (m> 0) { + a += m % 10; + m /= 10; + } + + int b = 0; + while (n> 0) { + b += n % 10; + n /= 10; + } + + return a + b <= target; + } + + int moving(int row, int col, vector>& arr, int i, int j, int target) { + int count = 0; + if (checksum(i, j, target) + && i>=0 && i < row && j>=0 && j < col + && arr[i][j] == 0) { + arr[i][j] = 1; + count = 1 + moving(row, col, arr, i-1, j, target) + + moving(row, col, arr, i, j-1, target) + + moving(row, col, arr, i+1, j, target) + + moving(row, col, arr, i, j+1, target); + } + + return count; + } + + int movingCount(int m, int n, int k) { + if (m == 0 || n == 0) { + return 0; + } + + vector> arr(m, vector(n, 0)); + int cnt = moving(m, n, arr, 0, 0, k); + return cnt; + } +}; +``` + ### **...** ``` diff --git "a/lcof/351円235円242円350円257円225円351円242円23013円. 346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円/Solution.cpp" "b/lcof/351円235円242円350円257円225円351円242円23013円. 346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円/Solution.cpp" new file mode 100644 index 0000000000000..e69de29bb2d1d From 3957de9238300955e86a58e5c900abcb85a05d82 Mon Sep 17 00:00:00 2001 From: "junfeng.fj" Date: 2021年1月24日 13:44:37 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0lcof-cpp=E7=89=88?= =?UTF-8?q?=E6=9C=AC[=E4=BB=8E=E4=B8=8A=E5=88=B0=E4=B8=8B=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E4=BA=8C=E5=8F=89=E6=A0=91]=E6=BA=90=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Solution.cpp" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "lcof/351円235円242円350円257円225円351円242円23032円 - I. 344円273円216円344円270円212円345円210円260円344円270円213円346円211円223円345円215円260円344円272円214円345円217円211円346円240円221円/Solution.cpp" diff --git "a/lcof/351円235円242円350円257円225円351円242円23032円 - I. 344円273円216円344円270円212円345円210円260円344円270円213円346円211円223円345円215円260円344円272円214円345円217円211円346円240円221円/Solution.cpp" "b/lcof/351円235円242円350円257円225円351円242円23032円 - I. 344円273円216円344円270円212円345円210円260円344円270円213円346円211円223円345円215円260円344円272円214円345円217円211円346円240円221円/Solution.cpp" new file mode 100644 index 0000000000000..1409ec6be0389 --- /dev/null +++ "b/lcof/351円235円242円350円257円225円351円242円23032円 - I. 344円273円216円344円270円212円345円210円260円344円270円213円346円211円223円345円215円260円344円272円214円345円217円211円346円240円221円/Solution.cpp" @@ -0,0 +1,37 @@ +/** + * Definition for a binary tree node. + * struct TreeNode { + * int val; + * TreeNode *left; + * TreeNode *right; + * TreeNode(int x) : val(x), left(NULL), right(NULL) {} + * }; + */ + +class Solution { +public: + vector levelOrder(TreeNode* root) { + vector ret; + if (!root) { + return ret; + } + + queue
q; + q.push(root); + + while (!q.empty()) { + auto head = q.front(); + q.pop(); + ret.push_back(head->val); + if (head->left) { + q.push(head->left); + } + + if (head->right) { + q.push(head->right); + } + } + + return ret; + } +}; \ No newline at end of file From 503895d4defa5873fdb797ca1df848b7342a5d56 Mon Sep 17 00:00:00 2001 From: Yang Libin Date: 2021年1月24日 14:23:17 +0800 Subject: [PATCH 3/4] Update README.md --- .../README.md" | 2 ++ 1 file changed, 2 insertions(+) diff --git "a/lcof/351円235円242円350円257円225円351円242円23013円. 346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円/README.md" "b/lcof/351円235円242円350円257円225円351円242円23013円. 346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円/README.md" index 160778737cbf1..dd5042b17a2a7 100644 --- "a/lcof/351円235円242円350円257円225円351円242円23013円. 346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円/README.md" +++ "b/lcof/351円235円242円350円257円225円351円242円23013円. 346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円/README.md" @@ -173,6 +173,8 @@ func dfs(x, y, m, n, k int, visited [][]bool) int { } ``` +### **C++** + ```cpp class Solution { public: From 3f88ae708f95efb03258233616369c0468106a64 Mon Sep 17 00:00:00 2001 From: Yang Libin Date: 2021年1月24日 14:23:45 +0800 Subject: [PATCH 4/4] Update Solution.cpp --- .../Solution.cpp" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git "a/lcof/351円235円242円350円257円225円351円242円23013円. 346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円/Solution.cpp" "b/lcof/351円235円242円350円257円225円351円242円23013円. 346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円/Solution.cpp" index e69de29bb2d1d..1d446cbb4cfac 100644 --- "a/lcof/351円235円242円350円257円225円351円242円23013円. 346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円/Solution.cpp" +++ "b/lcof/351円235円242円350円257円225円351円242円23013円. 346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円/Solution.cpp" @@ -0,0 +1,37 @@ +class Solution { +public: + int checksum(int m, int n, int target) { + int a = 0; + while (m> 0) { + a += m % 10; + m /= 10; + } + int b = 0; + while (n> 0) { + b += n % 10; + n /= 10; + } + return a + b <= target; + } + int moving(int row, int col, vector>& arr, int i, int j, int target) { + int count = 0; + if (checksum(i, j, target) + && i>=0 && i < row && j>=0 && j < col + && arr[i][j] == 0) { + arr[i][j] = 1; + count = 1 + moving(row, col, arr, i-1, j, target) + + moving(row, col, arr, i, j-1, target) + + moving(row, col, arr, i+1, j, target) + + moving(row, col, arr, i, j+1, target); + } + return count; + } + int movingCount(int m, int n, int k) { + if (m == 0 || n == 0) { + return 0; + } + vector> arr(m, vector(n, 0)); + int cnt = moving(m, n, arr, 0, 0, k); + return cnt; + } +};

AltStyle によって変換されたページ (->オリジナル) /