leetcode一些细节】的更多相关文章

本文senlie原版的,转载请保留此地址:http://blog.csdn.net/zhengsenlie Rotate Image Total Accepted: 15609 Total Submissions: 49679My Submissions You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up: Could you d…
取数组中点时不要写 int mid = (left + right) // 2;,「这么写有一个问题:数值越界,例如left和right都是最大int,这么操作就越界了,在二分法中尤其需要注意!」 所以可以这么写:int mid = left + ((right - left) // 2);…
Set Matrix Zeroes Total Accepted: 18139 Total Submissions: 58671My Submissions Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click to show follow up. 题意:给定矩阵,假设矩阵的某个位置为0.则把那一行那一列的全部元素都置为0 思路:用两个bool数组,分…
利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode.com/problems/longest-valid-parentheses/ (也可以用一维数组,贪心)http://oj.leetcode.com/problems/valid-parentheses/http://oj.leetcode.com/problems/largest-rectangle-in-histo…
花了将近 20 多天的业余时间,把 LeetCode 上面的题目做完了,毕竟还是针对面试的题目,代码量都不是特别大,难度和 OJ 上面也差了一大截. 关于二叉树和链表方面考察变成基本功的题目特别多,其次是一些简单的动态规划,但是感觉最有意思的还是一些能够在 O(n) 时间内解决的比较 tricky 的题目. 考察对于递归理解的题目也占了一定的比例,更多的时候还是判断一个人在细节方面的领悟程度吧. 没有特别难的题,难的是能一次性的 bug free. 我把代码传到了 https://github.…
July 16, 2015 Problem statement: Longest Substring Without Repeating Characters Read the blog: http://blog.csdn.net/fightforyourdream/article/details/17860983 这算法写了很多次, 时间太长, 半年前, 有一次写了二个小时, 写不下去, 想法不好, 没有办法收场; 接着, 又写了四天, 每天二小时, 把上次代码拿出来看, 有什么问题, 改写.…
463. Island Perimeterhttps://leetcode.com/problems/island-perimeter/就是逐一遍历所有的cell,用分离的cell总的的边数减去重叠的边的数目即可.在查找重叠的边的数目的时候有一点小技巧,就是沿着其中两个方向就好,这种题目都有类似的规律,就是可以沿着上三角或者下三角形的方向来做.一刷一次ac,但是还没开始注意codestyle的问题,需要再刷一遍. class Solution { public: int islandPerime…
题意:字符串转正数 原题来自:https://leetcode.com/problems/string-to-integer-atoi/ 分析: <程序员面试宝典>上出现的面试题,主要是考虑到细节. 1. 字串为空或者全是空格,返回0: 2. 字串的前缀空格需要忽略掉: 3. 忽略掉前缀空格后,遇到的第一个字符,如果是‘+’或‘-’号,继续往后读:如果是数字,则开始处理数字:如果不是前面的2种,返回0: 4. 处理数字的过程中,如果之后的字符非数字,就停止转换,返回当前值: 5. 在上述处理过…
题目描述: Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. For example,Given input array…
https://oj.leetcode.com/problems/string-to-integer-atoi/ 细节题,把一个字符串转换成整数 class Solution { public: int atoi(const char *str) { if(str == NULL) ; // remove all spaces ; while(str[i] != '/0' && str[i] == ' ') { i++; } // only contain spaces if(str[i]…