本题不清楚题意,从网上找到了python的解答,记录如下。

class Solution:
def numMagicSquaresInside(self, grid):
ans, lrc = 0, [len(grid), len(grid[0])]
def checkMagic(a,b, c, d, e, f, g ,h, i):
return (sorted([a,b,c,d,e,f,g,h,i]) == [i for i in range(1,10)] and
(a + b+c == d + e + f == g + h + i == a + d + g == b + e + h == c +f + i
== a + e + i == c + e + g == 15))
for i in range(1, lrc[0]-1):
for j in range(1, lrc[1]-1):
if grid[i][j] == 5 and checkMagic(grid[i-1][j-1], grid[i-1][j], grid[i-1][j+1],
grid[i][j-1], grid[i][j], grid[i][j+1],
grid[i+1][j-1], grid[i+1][j], grid[i+1][j+1]):
ans += 1
return ans

leetcode840的更多相关文章

  1. [Swift]LeetCode840. 矩阵中的幻方 | Magic Squares In Grid

    A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, co ...

  2. Leetcode840.Magic Squares In Grid矩阵中的幻方

    3 x 3 的幻方是一个填充有从 1 到 9 的不同数字的 3 x 3 矩阵,其中每行,每列以及两条对角线上的各数之和都相等. 给定一个由整数组成的 N × N 矩阵,其中有多少个 3 × 3 的 & ...

随机推荐

  1. vue中axios的深入使用

    如上所示一条简单的请求数据,用到了vue中axios,promise,qs等等 这里我将vue中用到的axios进行了封装方便日后使用  先对工具类进行封装utils/axios.js: // 引入模 ...

  2. [译]SSL/TLS真的被BEAST攻击攻破了吗?真实情况是怎样的?我应该做什么?

    原文链接:https://luxsci.com/blog/is-ssltls-really-broken-by-the-beast-attack-what-is-the-real-story-what ...

  3. UVALive - 4108 SKYLINE (吉司机线段树)

    题目链接 题意:在一条直线上依次建造n座建筑物,每座建筑物建造完成后询问它在多长的部分是最高的. 比较好想的方法是用线段树分别维护每个区间的最小值mi和最大值mx,当建造一座高度为x的建筑物时,若mi ...

  4. python(一):python语言基础

    一.python语言基本的8个要素 Python语言的8个要素:数据类型.对象引用.组合数据类型.逻辑操作符.运算操作符.控制流语句.输入/输出.函数的创建与引用.除此之外还有一个非常重要且无处不在的 ...

  5. LeetCode Number of Atoms

    原题链接在这里:https://leetcode.com/problems/number-of-atoms/description/ 题目: Given a chemical formula (giv ...

  6. YUYV&YV12&mtk6763

    stImgInOut.stImgInfo.enImageType = UV_IMAGE_TYPE_YV12; stImgInOut.stImgInfo.as32Pitch[0] = pStreamIm ...

  7. ballerina 学习五 使用composer管理ballerina 项目

    1. 启动 composer 备注: 因为这个命名和php的一个包管理工具重名了,所以可能需要使用决定路径 比如我的mac系统使用:Library/Ballerina/ballerina-0.970. ...

  8. drone 学习三 条件步骤

    1. 基本格式 pipeline: slack: image: plugins/slack channel: dev + when: + branch: master 2. 几种条件类型 a. bra ...

  9. Spring整合Quartz定时器

    1.添加jar #此处省略spring核心jar包 <dependency> <groupId>org.quartz-scheduler</groupId> < ...

  10. cowboy的get和post的例子

    官方get和post的代码是有问题的,1.1下运行crash,这里修改了下,贴代码 创建工程 rebar-creator create-app testCowboy testCowboy_app.er ...