🔥 BEATS 100% | ✅ [ Py /Java / C++ / C / C# / JS / GO / Rust ]
\nC++ []\nclass Solution {\npublic:\n    int numSubmatrixSumTarget(vector<vector<int>>& matrix, int target) {\n        int m = matrix.size(), n = matrix[0].size
\n```C++ []\nclass Solution {\npublic:\n    int numSubmatrixSumTarget(vector<vector<int>>& matrix, int target) {\n        int m = matrix.size(), n = matrix[0].size(), res = 0;\n\n        for (int l = 0; l < n; ++l) {\n            int sums[105] = {0};\n            for (int r = l; r < n; ++r) {\n                for (int i = 0; i < m; ++i) {\n                    sums[i] += matrix[i][r];\n                }\n                for (int i = 0; i < m; ++i) {\n                    int sum = 0;\n                    for (int j = i; j < m; ++j) {\n                        sum += sums[j];\n                        if (sum == target) {\n                            ++res;\n                        }\n                    }\n                }\n            }\n        }\n\n        return res;\n    }\n};\n\n```\n```Java []\nclass Solution {\n    public int numSubmatrixSumTarget(int[][] matrix, int target) {\n        int m = matrix.length, n = matrix[0].length, res = 0;\n\n        for (int l = 0; l < n; ++l) {\n            int[] sums = new int[105];\n            for (int r = l; r < n; ++r) {\n                for (int i = 0; i < m; ++i) {\n                    sums[i] += matrix[i][r];\n                }\n                for (int i = 0; i < m; ++i) {\n                    int sum = 0;\n                    for (int j = i; j < m; ++j) {\n                        sum += sums[j];\n                        if (sum == target) {\n                            ++res;\n                        }\n                    }\n                }\n            }\n        }\n\n        return res;\n    }\n}\n\n```\n```Python []\nclass Solution:\n    def numSubmatrixSumTarget(self, matrix: List[List[int]], target: int) -> int:\n        for row in matrix:\n            for i in range(len(row)-1):\n                row[i+1] += row[i]\n\n        count = 0\n        for t in range(len(matrix)):\n            for b in range(t, -1, -1):\n                if t == b:\n                    cur = matrix[t][:]\n                else:\n                    cur = [cur[i]+matrix[b][i] for i in range(len(matrix[0]))]\n                seen = {0: 1}\n                for v in cur:\n                    if v - target in seen:\n                        count += seen[v - target]\n                    seen[v] = seen.get(v, 0) + 1\n                    \n        return count\n# not same logic as other codes\n# for python it may not beat 100% .. \n\n```\n```C []\nint numSubmatrixSumTarget(int** matrix, int matrixSize, int* matrixColSize, int target) {\n    int m = matrixSize, n = *matrixColSize, res = 0;\n\n    for (int l = 0; l < n; ++l) {\n        int sums[105] = {0};\n        for (int r = l; r < n; ++r) {\n            for (int i = 0; i < m; ++i) {\n                sums[i] += matrix[i][r];\n            }\n            for (int i = 0; i < m; ++i) {\n                int sum = 0;\n                for (int j = i; j < m; ++j) {\n                    sum += sums[j];\n                    if (sum == target) {\n                        ++res;\n                    }\n                }\n            }\n        }\n    }\n\n    return res;\n}\n\n```\n```C# []\npublic class Solution {\n    public int NumSubmatrixSumTarget(int[][] matrix, int target) {\n        int m = matrix.Length, n = matrix[0].Length, res = 0;\n\n        for (int l = 0; l < n; ++l) {\n            int[] sums = new int[105];\n            for (int r = l; r < n; ++r) {\n                for (int i = 0; i < m; ++i) {\n                    sums[i] += matrix[i][r];\n                }\n                for (int i = 0; i < m; ++i) {\n                    int sum = 0;\n                    for (int j = i; j < m; ++j) {\n                        sum += sums[j];\n                        if (sum == target) {\n                            ++res;\n                        }\n                    }\n                }\n            }\n        }\n\n        return res;\n    }\n}\n\n```\n```Javascript []\nvar numSubmatrixSumTarget = function(matrix, target) {\n    let m = matrix.length, n = matrix[0].length;\n    let res = 0;\n\n    for (let l = 0; l < n; ++l) {\n        let sums = new Array(105).fill(0);\n        for (let r = l; r < n; ++r) {\n            for (let i = 0; i < m; ++i) {\n                sums[i] += matrix[i][r];\n            }\n            for (let i = 0; i < m; ++i) {\n                let sum = 0;\n                for (let j = i; j < m; ++j) {\n                    sum += sums[j];\n                    if (sum === target) {\n                        ++res;\n                    }\n                }\n            }\n        }\n    }\n\n    return res;\n};\n\n```\n```GO []\nfunc numSubmatrixSumTarget(matrix [][]int, target int) int {\n    m, n := len(matrix), len(matrix[0])\n    res := 0\n\n    for l := 0; l < n; l++ {\n        sums := make([]int, 105)\n        for r := l; r < n; r++ {\n            for i := 0; i < m; i++ {\n                sums[i] += matrix[i][r]\n            }\n            for i := 0; i < m; i++ {\n                sum := 0\n                for j := i; j < m; j++ {\n                    sum += sums[j]\n                    if sum == target {\n                        res++\n                    }\n                }\n            }\n        }\n    }\n\n    return res\n}\n\n```\n```Rust []\nimpl Solution {\n    pub fn num_submatrix_sum_target(matrix: Vec<Vec<i32>>, target: i32) -> i32 {\n        let (m, n) = (matrix.len(), matrix[0].len());\n        let mut res = 0;\n\n        for l in 0..n {\n            let mut sums = vec![0; 105];\n            for r in l..n {\n                for i in 0..m {\n                    sums[i] += matrix[i][r];\n                }\n                for i in 0..m {\n                    let mut sum = 0;\n                    for j in i..m {\n                        sum += sums[j];\n                        if sum == target {\n                            res += 1;\n                        }\n                    }\n                }\n            }\n        }\n\n        res\n    }\n}\n\n```\n**\u041F\u043E \u0440\u0435\u0448\u0435\u043D\u0438\u044E \u043D\u0430 \u0421++ \u0434\u043E\u0441\u0442\u0438\u0433\u0430\u0435\u0442 100%, \u043F\u043E \u043E\u0441\u0442\u0430\u043B\u044C\u043D\u044B\u043C \u043A\u043E\u0434\u0430\u043C \u043D\u0435 \u0437\u043D\u0430\u044E..\n\u043F\u0440\u043E\u0433\u043E\u043B\u043E\u0441\u0443\u0439\u0442\u0435 \u043F\u043E\u0436\u0430\u043B\u0443\u0439\u0441\u0442\u0430!! \uD83D\uDE0A**\n
['C', 'Python', 'C++', 'Java', 'Go', 'Python3', 'Rust', 'JavaScript', 'C#']