似乎可以沿着对角线往右往下检查,也可以正常按题设检查。

我用的后者。。

public class Solution
{
public boolean validWordSquare(List<String> words)
{
if(words.size() <= 1) return true;
if(words.size() != words.get(0).length()) return false; for(int i = 0; i < words.get(0).length();i++)
{
String s = words.get(i);
if(s.length() > words.size()) return false;
for(int j = 0; j <s.length();j++)
{
if(i >= words.get(j).length()) return false;
if(s.charAt(j) != words.get(j).charAt(i)) return false;
} } return true;
}
}



二刷。

尝试了对角线,居然卡了…… 老老实实正常做了。

逐渐在适应 GOOGLE JAVA DOC STYLE的排版。

public class Solution {
public boolean validWordSquare(List<String> words) {
if (words.size() == 0) return true;
if (words.size() != words.get(0).length()) return false; for (int i = 0; i < words.size(); i++) {
String tempStr = words.get(i);
if (tempStr.length() > words.size()) return false;
for (int j = 0; j < tempStr.length(); j++) {
if (words.get(j).length() <= i) return false;
if (words.get(j).charAt(i) != tempStr.charAt(j)) return false; }
} return true;
}
}

今天一直心神不定,各种卡,可能心里有事吧,在担心下周一的电面,每遇到一下子想不出的题,就觉得如果在电面中遇到不是吃屎了。。这个心理素质,也是没谁了。

好烦躁。

422. Valid Word Square的更多相关文章

  1. LeetCode 422. Valid Word Square

    原题链接在这里:https://leetcode.com/problems/valid-word-square/ 题目: Given a sequence of words, check whethe ...

  2. 【LeetCode】422. Valid Word Square 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 拼接出每一列的字符串 日期 题目地址:https:// ...

  3. [LeetCode] Valid Word Square 验证单词平方

    Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a v ...

  4. Leetcode: Valid Word Square

    Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a v ...

  5. [LeetCode] 422. Valid Word Square_Easy

    Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a v ...

  6. 367. Valid Perfect Square

    原题: 367. Valid Perfect Square 读题: 求一个整数是否为完全平方数,如1,4,9,16,……就是完全平方数,这题主要是运算效率问题 求解方法1:812ms class So ...

  7. Leetcode之二分法专题-367. 有效的完全平方数(Valid Perfect Square)

    Leetcode之二分法专题-367. 有效的完全平方数(Valid Perfect Square) 给定一个正整数 num,编写一个函数,如果 num 是一个完全平方数,则返回 True,否则返回 ...

  8. LeetCode_367. Valid Perfect Square

    367. Valid Perfect Square Easy Given a positive integer num, write a function which returns True if  ...

  9. [LeetCode] Valid Word Abbreviation 验证单词缩写

    Given a non-empty string s and an abbreviation abbr, return whether the string matches with the give ...

随机推荐

  1. 用Ueditor存入数据库带HTML标签的文本,从数据库取出来后,anjular用ng-bind-html处理带HTML标签的文本

    ng.module('index-filters', []) .filter('trustHtml', function ($sce) { return function (input) { retu ...

  2. RAC配置、安装

    RAC  配置及安装 2012年12月30日 星期日 21:49 ******************************************************************* ...

  3. ajax 操作全局监测,用户session失效

    jQuery(function ($) { // 备份jquery的ajax方法 var _ajax = $.ajax; // 重写ajax方法,先判断登录在执行success函数 $.ajax = ...

  4. 你好,C++(3)2.1 一个C++程序的自白

    第2部分 与C++第一次亲密接触 在浏览了C++“三分天下”的世界版图之后,便对C++有了基本的了解,算是一只脚跨入了C++世界的大门.那么,怎样将我们的另外一只脚也跨入C++世界的大门呢?是该即刻开 ...

  5. LA 6856 Circle of digits 解题报告

    题目链接 先用后缀数组给串排好序.dc3 O(n) 二分答案+贪心check 答案的长度len=(n+k-1)/k 如果起点为i长为len串大于当前枚举的答案,i的长度取len-1 从起点判断k个串的 ...

  6. Queue学习

    Queue在Python中可以算作是一种容器,但是他和list,set,dict不一样. 1. Queue不是Python内置类型.它在Queue模块中定义. 2. 它不是iterator容器,他不能 ...

  7. 用jq 做了一个排序

    <ul id="cont"> <li data="5">5</li> <li data="1"&g ...

  8. Rewrite的QSA是什么意思?

    原版的英文: When the replacement URI contains a query string, the default behavior of RewriteRule is to d ...

  9. java-web-j2e学习建议路线

      JAVA学习之路(2)  首先要明白Java体系设计到得三个方面:J2SE,J2EE,J2ME(KJAVA).J2SE,Java 2 Platform Standard Edition,我们经常说 ...

  10. 架设wordpress再vps上的 一些感想总结

    日本vps.樱花系列 配置: 2cpu+1G内存+100G硬盘 系统 第一次我把默认的centos 给换了..原因就是,不会linux.而且我主要用.net  感觉 mono也行.但是linux不会. ...