422. Valid Word Square
似乎可以沿着对角线往右往下检查,也可以正常按题设检查。
我用的后者。。
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的更多相关文章
- LeetCode 422. Valid Word Square
原题链接在这里:https://leetcode.com/problems/valid-word-square/ 题目: Given a sequence of words, check whethe ...
- 【LeetCode】422. Valid Word Square 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 拼接出每一列的字符串 日期 题目地址:https:// ...
- [LeetCode] Valid Word Square 验证单词平方
Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a v ...
- Leetcode: Valid Word Square
Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a v ...
- [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 ...
- 367. Valid Perfect Square
原题: 367. Valid Perfect Square 读题: 求一个整数是否为完全平方数,如1,4,9,16,……就是完全平方数,这题主要是运算效率问题 求解方法1:812ms class So ...
- Leetcode之二分法专题-367. 有效的完全平方数(Valid Perfect Square)
Leetcode之二分法专题-367. 有效的完全平方数(Valid Perfect Square) 给定一个正整数 num,编写一个函数,如果 num 是一个完全平方数,则返回 True,否则返回 ...
- LeetCode_367. Valid Perfect Square
367. Valid Perfect Square Easy Given a positive integer num, write a function which returns True if ...
- [LeetCode] Valid Word Abbreviation 验证单词缩写
Given a non-empty string s and an abbreviation abbr, return whether the string matches with the give ...
随机推荐
- Java 获取字符串中第N次出现的字符位置
public static int getCharacterPosition(String string){ //这里是获取"/"符号的位置 Matcher slash ...
- Win10获取管理员/administrator权限的方法
与Win7不同,Win10右键文件夹菜单,是没有“获取管理员权限”这个功能的,但是有时候我们偏偏需要用到这个功能,怎么办呢,可以按照这个办法实现:把下面的这一段代码复制下来放在文本文档中,然后另存为. ...
- UIView用户事件响应
UIView除了负责展示内容给用户外还负责响应用户事件.本章主要介绍UIView用户交互相关的属性和方法. 1.交互相关的属性 userInteractionEnabled 默认是YES ,如果设置为 ...
- iOS6以后的单个控制器横竖屏显示以及旋转屏控制技巧,附带iOS8以后显示电池状态栏
一.在应用中从竖屏模式强制转换为横屏模式 第一种方法:通过模态弹出视图的方式,使得特定ViewController坚持特定的interfaceOrientation(1)iOS6之后提供了这样一个方法 ...
- js判断是否在iframe中
1.方式一 if (self.frameElement && self.frameElement.tagName == "IFRAME") { alert('在if ...
- IoC模式(控制反转)(转)
转自:http://www.cnblogs.com/qqlin/archive/2012/10/09/2707075.html,写的很好,用C#代码解释控制反转,然后更进一步,提到依赖注入是控制反转的 ...
- Oracle 面试宝典 - General Questions
转自 http://www.orafaq.com/wiki/Interview_Questions Tell us about yourself/ your background. What are ...
- php之分页类代码
/* 思路 1.把地址栏的URL获取 2.分析URL中的query部分--就是?后面传参数的部分 3.query部分分析成数组 4.把数组中的page单元,+1,-1,形成2个新的数组 5.再把新数组 ...
- [Winfrom] 捕获窗体最大化、最小化和关闭按钮的事件
const int WM_SYSCOMMAND = 0x112;const int SC_CLOSE = 0xF060;const int SC_MINIMIZE = 0xF020;const int ...
- 原生Js获取某个节点后面的第一个标签
nextSlbling属性 获取某个节点后面的第一个节点(可能是标签 文本) 判断获取的节点是否为标签节点还是文本节点 window.onload=function(){ var pagecount= ...