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. C++ 模板元编程 学习笔记

    https://blog.csdn.net/K346K346/article/details/82748163 https://www.jianshu.com/p/b56d59f77d53 https ...

  2. 小数据池/is和==/再谈编码作业

    # 1,老男孩好声选秀大赛评委在打分的时候呢, 可以输入分数. 假设, 老男孩有10个评委. 让10个评委进行打分, 要求, 分数必须高于5分, 低于10分.将每个评委的打分情况保存在列表中. pin ...

  3. Connection to newtaotao failed. [08001] Could not create connection to database

    jdbc.url=jdbc:mysql://localhost:3306/newtaotao?serverTimezone=UTC&characterEncoding=utf-8 数据库是5. ...

  4. Linux最大线程数限制

    开始以为是内存不足导致无法创建线程,把jvm的-Xms,-Xmx的2个参数都加大一倍:-Xms2048m -Xmx2048m.把-Xss参数调小,还是启动失败.应该是系统方面的限制了,这台机器上搞了1 ...

  5. 帝国CMS排行榜调用标签

    [e:loop={0,9,4,0,'newstime>UNIX_TIMESTAMP()-86400*30','onclick desc'}]<li><a href=" ...

  6. hdoj - 2602 Bone Collector

    Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...

  7. Ubuntu系统之Hadoop搭建

    作业来源:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/3223 一.在Window中安装Oracle VM VirtualBox 二 ...

  8. Android HIDL学习(2) ---- HelloWorld【转】

    本文转载自: 写在前面 程序员有个癖好,无论是学习什么新知识,都喜欢以HelloWorld作为一个简单的例子来开头,咱们也不例外. OK,咱这里都是干货,废话就不多说啦,学习HIDL呢咱们还是需要一些 ...

  9. PLSQL Developer连接远程oracle配置(详细解读)

    转自:https://blog.csdn.net/zhige_j/article/details/80832654 一.安装Instant Client 1. 下载Instant Client(轻量级 ...

  10. Visual Studio 2017 vcvarsall.bat 环境配置对应关系

    博客参考:https://chenzehe.iteye.com/blog/1703429 安装Visual Studio 2017之后,vcvarsall.bat ,vcvars32.bat,vcva ...