Swift💯1liner
One-Liner, terse \uD83D\uDE44 (accepted answer)\n\nclass Solution {\n    func numSubmatrixSumTarget(_ m: [[Int]], _ t: Int) -> Int {\n        m[0].indices.reduc
**One-Liner, terse \uD83D\uDE44 (accepted answer)**\n```\nclass Solution {\n    func numSubmatrixSumTarget(_ m: [[Int]], _ t: Int) -> Int {\n        m[0].indices.reduce((0,m.map{$0.reduce(into:[0]){$0+=[$0.last!+$1]}})){d,i in ((i..<d.1[0].count-1).reduce(d.0){r,j in d.1.reduce(into:(r,[0:1],0)){a,b in a.2+=b[j+1]-b[i];a.0+=a.1[a.2-t] ?? 0;a.1[a.2,default:0]+=1}.0},d.1)}.0\n    }\n}\n```\n\n---\n\n**One-Liner, expanded and annotated (accepted answer)**\n```\nimport Algorithms\n\nclass Solution {\n    func numSubmatrixSumTarget(_ matrix: [[Int]], _ target: Int) -> Int {\n        matrix[0].indices.reduce(0) { result, i in\n            (i..<matrix[0].count).reduce(result) {result, j in\n                matrix.reduce(into: (\n                        result: result,\n                        counts: [0:1],\n                        cur:    0\n                )) { data, row in\n                    let prefixSums = row.reductions(0, +)\n                    data.cur += prefixSums[j+1] - prefixSums[i]\n                    data.result += data.counts[data.cur - target, default:0]\n                    data.counts[data.cur, default:0] += 1\n                }\n                .result\n            }\n        }\n    }\n}\n```
['Swift']