摘要:
少数次过 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNo... 阅读全文
摘要:
看了网上答案,发现一个很有趣的问题,check函数里形参board是传值时(即&board)速度很快,能过large,去掉这个&后就过不了large了,是不是因为没有传值的话每次需要复制这样耗了时间了呢 1 class Solution { 2 public: 3 bool check(in... 阅读全文
摘要:
自己想的大体思路还是对的,不过可以改进的很多,最后网上找了个勉勉强强过large的答案,用map实在太容易超时了。。 1 class Solution { 2 public: 3 vector findSubstring(string S, vector &L) { 4 //... 阅读全文
摘要:
这题自己没想出来看了网上答案,才知道只要在上一题的基础上改用set而不用vector就可以了,set和vector的区别就在于set里没有重复元素,只要用set.insert(*), 会自动识别是否重复。set好牛逼。。 1 class Solution { 2 public: 3 void dfs(int cur, int n, set<vector<int>> &T, vector<int> &tmp, vector<int> S) { 4 if (cur == n) { 5 T.insert(tmp); 6 retu... 阅读全文
摘要:
脑子有点混,少数次过 1 class Solution { 2 public: 3 void dfs(int cur, int n, vector> &ret, vector &tmp, vector S) { 4 if (cur == n) { 5 ... 阅读全文
摘要:
这种题就是考你考虑了多少些情况,第一次没有考虑到的情况有:+-号,超出int范围,多数次过 1 class Solution { 2 public: 3 int atoi(const char *str) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 bool showed = false; 7 int s = 0; 8 bool negtive = false; 9 ... 阅读全文
摘要:
一点小失误,基本一次过吧 1 class Solution { 2 public: 3 int sqrt(int x) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int ma... 阅读全文
摘要:
一次过 1 class Solution { 2 public: 3 bool out(int x, int y, int n) { 4 if (x >= n || x = n || y > &ret, int dir[4][2], int dep, int n, int d... 阅读全文
摘要:
多数次过。很奇怪dfs函数声明的时候形参里dir[][]不能用,必须为dir[4][2]. 1 class Solution { 2 public: 3 bool out(int x, int y, int m, int n) { 4 if (x >= m || x = n ... 阅读全文
摘要:
没写出来,看到网上一个非常好的code,不过这个code不太容易想出来 1 class Solution { 2 public: 3 void sortColors(int A[], int n) { 4 // Start typing your C/C++ solution... 阅读全文
摘要:
改了很多次,这种麻烦的题目就是考你有没有考虑到所有情况 1 class Solution { 2 public: 3 string simplifyPath(string path) { 4 // Start typing your C/C++ solution below ... 阅读全文
摘要:
Java: 需要注意的是,题目要求不能有额外的空间,因此我们需要在矩阵上进行操作,不能直接将行和列置0,因此我们需要存储各行列的状态,但是首行首列的状态不能存在matrix[0][0]中,需要两个boolean变量来存储,而这两个boolean变量的初值则是matrix[0][0] == 0 阅读全文
摘要:
一次过 1 class Solution { 2 public: 3 int searchInsert(int A[], int n, int target) { 4 // Start typing your C/C++ solution below 5 //... 阅读全文
摘要:
搞了很久始终没通过,看了网上的简单答案,这道题的关键在于看target处于哪段递增区间里 1 class Solution { 2 public: 3 bool search(int A[], int n, int target) { 4 // Start typing yo... 阅读全文
摘要:
少数次过 1 class Solution { 2 public: 3 int search(int A[], int n, int target) { 4 // Start typing your C/C++ solution below 5 // DO N... 阅读全文