Update 刷题.md

pull/46/head
JZFamily 2018-06-24 12:19:19 +08:00 committed by GitHub
parent a75f27b606
commit 83f884f5a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 116 additions and 0 deletions

View File

@ -573,5 +573,121 @@ public:
}
};
```
# 28. 实现strStr() @2018/06/23
### jzf
* 第一版 4ms
```c++
class Solution {
public:
int strStr(string haystack, string needle) {
string::iterator ihay;
string::iterator inee;
int ni =haystack.size();
int nn =needle.size();
int ret = -1;
if(nn==0)
{
return 0;
}
if(ni<nn)
{
return -1;
}
for(size_t i=0;i<ni-nn+1;i++)
{
if(!(haystack.substr(i,nn)).compare(needle))
{
ret =i;
break;
}
}
return ret;
}
};
```
### 羽柔子
```c++
class Solution {
public:
int strStr(string haystack, string needle) {
if(needle.size()==0)return 0;
if(haystack.size()<needle.size())return -1;
size_t
i,j,
ilen=haystack.size()-needle.size(),
jlen=needle.size();
for( i = 0; i <= ilen; i++){
for( j = 0; j < jlen; j++)
if(haystack[i+j]!=needle[j])
goto A;
return i;
A:;
}
return -1;
}
};
```
### puck
```c++
class Solution
{
public:
int strStr(string haystack, string needle)
{
std::size_t size_a{haystack.size()};
std::size_t size_b{needle.size()};
if (0 == size_b)
{
return 0;
}
bool flag{};
for (int i{}; i < size_a; ++i)
{
if (haystack.at(i) == needle.at(0))
{
flag = true;
for (int j{1}; j < size_b; ++j)
{
if (i + j >= size_a || haystack.at(i + j) != needle.at(j))
{
flag = false;
break;
}
}
if (flag)
{
return i;
}
}
}
return -1;
}
};
```
### 北河
## 823. Binary Trees With Factors@2018/06/23
## 196. 删除重复的电子邮箱@2018/06/23
### 北河
*
```sql
delete from Person where id in (select c.id from (select a.id from Person a join Person b on a.Email = b.Email and a.Id > b.Id) c);
```