package y2019.Algorithm.array;

/**
* @ProjectName: cutter-point
* @Package: y2019.Algorithm.array
* @ClassName: IsToeplitzMatrix
* @Author: xiaof
* @Description: 766. Toeplitz Matrix
* A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element.
* Now given an M x N matrix, return True if and only if the matrix is Toeplitz.
*
* Input:
* matrix = [
* [1,2,3,4],
* [5,1,2,3],
* [9,5,1,2]
* ]
* Output: True
* Explanation:
* In the above grid, the diagonals are:
* "[9]", "[5, 5]", "[1, 1, 1]", "[2, 2, 2]", "[3, 3]", "[4]".
* In each diagonal all elements are the same, so the answer is True.
*
* @Date: 2019/7/4 19:47
* @Version: 1.0
*/
public class IsToeplitzMatrix { public boolean solution(int[][] matrix) {
//就是比较斜线上是否是通一个数据
//每一斜线
//每次可以和下一行的斜线比较,这样依次比较
for(int i = 0; i < matrix.length - 1; ++i) {
for(int j = 0; j < matrix[i].length - 1; ++j) {
if(matrix[i][j] != matrix[i + 1][j + 1]) {
return false;
}
}
}
return true;
} public boolean isToeplitzMatrix(int[][] matrix) {
for (int i = 0; i < matrix.length - 1; i++) {
for (int j = 0; j < matrix[i].length - 1; j++) {
if (matrix[i][j] != matrix[i + 1][j + 1]) return false;
}
}
return true;
} public static void main(String args[]) { int[][] matrix = {{1,2,3,4},{5,1,2,3},{9,5,1,2}}; IsToeplitzMatrix fuc = new IsToeplitzMatrix();
System.out.println(fuc.isToeplitzMatrix(matrix));
} }

【LEETCODE】45、766. Toeplitz Matrix的更多相关文章

  1. 【LEETCODE】48、867. Transpose Matrix

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...

  2. 【LeetCode】9、Palindrome Number(回文数)

    题目等级:Easy 题目描述: Determine whether an integer is a palindrome. An integer is a palindrome when it rea ...

  3. 【LeetCode】 454、四数之和 II

    题目等级:4Sum II(Medium) 题目描述: Given four lists A, B, C, D of integer values, compute how many tuples (i ...

  4. 【LeetCode】18、四数之和

    题目等级:4Sum(Medium) 题目描述: Given an array nums of n integers and an integer target, are there elements ...

  5. 【LeetCode】15、三数之和为0

    题目等级:3Sum(Medium) 题目描述: Given an array nums of n integers, are there elements a, b, c in nums such t ...

  6. 【LeetCode】714、买卖股票的最佳时机含手续费

    Best Time to Buy and Sell Stock with Transaction Fee 题目等级:Medium 题目描述: Your are given an array of in ...

  7. 【LeetCode】74. Search a 2D Matrix

    Difficulty:medium  More:[目录]LeetCode Java实现 Description Write an efficient algorithm that searches f ...

  8. 【LeetCode】4、Median of Two Sorted Arrays

    题目等级:Hard 题目描述:   There are two sorted arrays nums1 and nums2 of size m and n respectively.   Find t ...

  9. 【LeetCode】2、Add Two Numbers

    题目等级:Medium 题目描述:   You are given two non-empty linked lists representing two non-negative integers. ...

随机推荐

  1. /etc/rc.local

    /etc/rc.local是/etc/rc.d/rc.local的软连接 应用于指定开机启动的进程 开机启动不生效,则首先需要检查下/etc/rc.d/rc.local是否具有可执行权限 在配置文件中 ...

  2. CF1237C2 【Balanced Removals (Harder)】

    这么妙的题怎么没人发题解啊 首先这是三维的,我们可以对其进行降维打击 先考虑一维怎么做? 我们可以对其该维坐标进行排序,按照顺序输出,可能会多余一个 那拓展到二维呢? 我们可以把它转化成一维,分成很多 ...

  3. Pandas的基本用法

    Pandas是使用python进行数据分析不可或缺的第三方库.我们已经知道,NumPy的ndarray数据结构能够很好地进行数组运算,但是当我们需要进行为数据添加标签,处理缺失值,对数据分组,创建透视 ...

  4. Balanced Ternary String(贪心+思维)

    题目链接:Balanced Ternary String 题目大意:给一个字符串,这个字符串只由0,1,2构成,然后让替换字符,使得在替换字符次数最少的前提下,使新获得的字符串中0,1,2 这三个字符 ...

  5. mysql 设置字段是否可以为null

    //不允许为null alter table table1 change id id ) not null; //允许为null alter table table1 change id id ) n ...

  6. Linux 文件系统磁盘空间与连接文件

    磁盘与目录的容量 我们知道磁盘的整体数据hi在superblock块中,但是各文件的容量则在inode中记载. df:列出文件系统的整体磁盘使用量 由于df主要读取的数据几乎都是针对整个文件系统,因此 ...

  7. 移动端 - adb shell常用命令

    一.文件操作相关命令 //进入设备 adb shell //进入指定目录"/data/local/tmp" cd /data/local/tmp //查看目录 ls //进入根目录 ...

  8. Hive(一)—— 启动与基本使用

    一.基本概念 Hive用于解决海量结构化日志的数据统计问题. Hive是基于Hadoop的一个数据仓库工具.本质是将HQL(Hive的查询语言)转化成MapReduce程序. HIve处理的数据存储在 ...

  9. FusionInsight,一个融合的大数据平台

    随着物联网技术和应用的普及,以运营商.互联网以及实体经济行业为代表的企业产生了越来越多的数据,大数据的发展越来越蓬勃. 从2007年开始,大数据应用成为很多企业的需求,2012年兴起并产生了大数据平台 ...

  10. Git创建与合并分支,撤销修改

    git回滚到指定版本并推送到远程分支(撤销已提交的修改,并已push) git reset --hard <commit ID号> git push -f git回滚到上一个版本并推送到远 ...