随笔分类 - 遍历
摘要:The general solution would be to check each char in turn and report the first char that makes the string a non number. There are some exceptions to wa
阅读全文
摘要:This solution is just a java version derived from this post. At first, lets look at the edge cases - Now the main algorithm works in following steps -
阅读全文
摘要:Example 2: Example 3: The logic is very similar to NO.347 and here we just use a map a count and according to the frequency to put it into the right b
阅读全文
摘要:第一想法是用HashSet<ListNode>, A list先遍历,存HashSet,然后B list遍历,发现ListNode存在就返回。但是这个方法不满足O(1)memory的要求。 再想了一会儿,略微受了点提醒,发现可以利用这个O(n) time做文章。这个条件方便我们scan list几次
阅读全文
摘要:Leetcode 12, 13(需要考虑输入不合法的情况,比如“VV”或者“IIII”都是不合法的输入,要输出错误信息): if (s.indexOf(II) .. throw new A.... 如今我们最常见的罗马数字就是钟表的表盘符号:Ⅰ,Ⅱ,Ⅲ,Ⅳ(IIII),Ⅴ,Ⅵ,Ⅶ,Ⅷ,Ⅸ,Ⅹ,Ⅺ,Ⅻ
阅读全文
摘要:这是一个矩阵操作的题目,目标很明确,就是如果矩阵如果有元素为0,就把对应的行和列上面的元素都置为0。这里最大的问题就是我们遇到0的时候不能直接把矩阵的行列在当前矩阵直接置0,否则后面还没访问到的会被当成原来是0,最后会把很多不该置0的行列都置0了。一个直接的想法是备份一个矩阵,然后在备份矩阵上判断,
阅读全文
摘要:根据题目的条件: 只有充分挖掘利用才行啊 键值对!!! 将值作为键, 并置为负来判断是否遍历过
阅读全文
摘要:Boyer-Moore Majority Vote algorithm The essential concepts is you keep a counter for the majority number X. If you find a number Y that is not X, the
阅读全文
摘要:这种考subarray sum 常用到累加和数组啊, 要清楚从哪到哪开始求和, 在看题意怎么判断就ok了, 数组subarray sum 问题常常用累加和基础上改变 没想到用hashmap O(n) 即可, 关键是存的都是k的余数, 然后余数相见等于零即可 if (k != 0) runningSu
阅读全文

浙公网安备 33010602011771号