Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
7e74c02
Create 超能炸弹人.md
wyfdream Nov 24, 2018
07bee36
Merge pull request #1 from wyfdream/wyfdream-patch-1
wyfdream Nov 24, 2018
e364e08
Create 大魔王爱穿孖烟筒.md
xinlawliet Nov 24, 2018
1f05457
Merge pull request #1 from xinlawliet/大魔王爱穿孖烟筒-patch-1
xinlawliet Nov 24, 2018
c3d7439
Merge pull request #14 from xinlawliet/master
gzc426 Nov 24, 2018
3d551f6
Merge pull request #13 from wyfdream/master
gzc426 Nov 24, 2018
689878b
Delete 1.md
gzc426 Nov 24, 2018
89f0016
Delete 2.md
gzc426 Nov 24, 2018
6cd8267
Delete testtest!
gzc426 Nov 24, 2018
1308029
Delete 微信名字.md
gzc426 Nov 24, 2018
560fc6e
Delete 变化.md
gzc426 Nov 24, 2018
0b6003b
Create zzz.md
bihailantian21 Nov 24, 2018
35d64c6
Merge pull request #1 from bihailantian21/bihailantian21-patch-1
bihailantian21 Nov 24, 2018
65c1029
Merge pull request #2 from gzc426/master
bihailantian21 Nov 24, 2018
548e32c
Merge pull request #15 from bihailantian21/master
gzc426 Nov 24, 2018
540e071
Update 超能炸弹人.md
wyfdream Nov 24, 2018
049c640
Merge pull request #2 from wyfdream/wyfdream-patch-2
wyfdream Nov 24, 2018
4f448ce
Create readMe
gzc426 Nov 24, 2018
a5b6956
Create readme.md
gzc426 Nov 24, 2018
d873665
Create 1.md
gzc426 Nov 24, 2018
60bc5f6
Create 1.md
gzc426 Nov 24, 2018
237976e
Create 1.md
gzc426 Nov 24, 2018
8567a0b
Create 1.md
gzc426 Nov 24, 2018
ad7e580
Create 1.md
gzc426 Nov 24, 2018
b6e7837
Create 句子.md
codemongkey Nov 24, 2018
b0cbd40
Create 句子.md
codemongkey Nov 24, 2018
d2636e7
Create 1.md
gzc426 Nov 24, 2018
6ca0e36
Update 乔戈里.md
gzc426 Nov 24, 2018
deb4183
Create 1.md
gzc426 Nov 24, 2018
8583f17
Create 句子.md
codemongkey Nov 24, 2018
641ab6e
Delete 句子.md
codemongkey Nov 24, 2018
f1b2406
Create 句子.md
codemongkey Nov 24, 2018
e8da264
Merge pull request #1 from codemongkey/codemongkey-patch-1
codemongkey Nov 24, 2018
9161f6b
Merge pull request #18 from codemongkey/patch-2
gzc426 Nov 24, 2018
57cf71a
Merge pull request #16 from wyfdream/master
gzc426 Nov 24, 2018
59bec55
Merge pull request #17 from codemongkey/patch-1
gzc426 Nov 24, 2018
d8ae6bf
Merge branch 'master' into master
gzc426 Nov 24, 2018
93908da
Merge pull request #19 from codemongkey/master
gzc426 Nov 24, 2018
be7a853
Create 1.md
gzc426 Nov 24, 2018
636cbbb
Delete readMe
gzc426 Nov 24, 2018
958a807
Create 张小胖.md
zchoas Nov 24, 2018
1746e09
Merge pull request #2 from gzc426/master
codemongkey Nov 24, 2018
7b4a4e0
Merge pull request #1 from zchoas/zchoas-patch-1
zchoas Nov 24, 2018
06b820e
Create kiritocly
Mrkirito Nov 24, 2018
9ca9912
Merge pull request #1 from Mrkirito/Mrkirito-patch-1
Mrkirito Nov 24, 2018
d928369
Create 句子.md
codemongkey Nov 24, 2018
d60b908
Create 忆季落花.md
black107 Nov 24, 2018
592df6a
Merge pull request #1 from black107/black107-patch-2
black107 Nov 24, 2018
67e4d4a
Create juzi.md
codemongkey Nov 24, 2018
ef399a8
Merge pull request #3 from codemongkey/codemongkey-patch-2
codemongkey Nov 24, 2018
5699c12
Delete juzi.md
codemongkey Nov 24, 2018
ab5cc98
Create leeboolean
leeboolean Nov 24, 2018
3fed852
Merge pull request #1 from leeboolean/leeboolean-patch-1
leeboolean Nov 24, 2018
5dd4c46
Merge pull request #24 from leeboolean/master
gzc426 Nov 24, 2018
de26358
Merge pull request #23 from black107/master
gzc426 Nov 24, 2018
efe6f98
Merge pull request #22 from codemongkey/master
gzc426 Nov 24, 2018
2d69006
Merge pull request #21 from Mrkirito/master
gzc426 Nov 24, 2018
c31faf3
Merge pull request #20 from zchoas/master
gzc426 Nov 24, 2018
3164f87
Create 湛江甲鸟.md
zjduck0728 Nov 25, 2018
bbed4cf
Merge pull request #1 from a-yin/a-yin-patch-1
zjduck0728 Nov 25, 2018
41996b1
Create OCEAN_he95.md
hhy1995 Nov 25, 2018
438d907
Merge pull request #1 from hhy1995/hhy1995-patch-1
hhy1995 Nov 25, 2018
967b741
Create sourcema.md
MMzhe Nov 25, 2018
528df99
Create sourcema.md
MMzhe Nov 25, 2018
98b7928
Merge pull request #28 from MMzhe/patch-2
gzc426 Nov 25, 2018
1721c87
Merge pull request #27 from MMzhe/patch-1
gzc426 Nov 25, 2018
e4d1704
Merge pull request #26 from hhy1995/master
gzc426 Nov 25, 2018
f651ae2
Merge pull request #25 from a-yin/master
gzc426 Nov 25, 2018
a2a398e
Rename 2019.11.25-leetcode80/1.md to 2018.11.25-leetcode80/1.md
gzc426 Nov 25, 2018
474db73
Rename 2019.11.15/1.md to 2018.11.15/1.md
gzc426 Nov 25, 2018
9919521
Rename 2019.11.16/1.md to 2018.11.16/1.md
gzc426 Nov 25, 2018
f5b0f2c
Update and rename 2019.11.17/1.md to 2018.11.17/1.md
gzc426 Nov 25, 2018
4c8b87a
Update and rename 2019.11.18/1.md to 2018.11.18/1.md
gzc426 Nov 25, 2018
764b7ad
Create 张小胖.md
zchoas Nov 25, 2018
c988086
Merge pull request #1 from zchoas/zchoas-patch-1
zchoas Nov 25, 2018
2b46c08
Update and rename 2019.11.19/1.md to 2018.11.19/1.md
gzc426 Nov 25, 2018
f2b9c7b
Rename 2019.11.20/1.md to 2018.11.20/1.md
gzc426 Nov 25, 2018
0902501
Rename 2019.11.21/1.md to 2018.11.21/1.md
gzc426 Nov 25, 2018
09d677c
Rename 2019.11.22/readme.md to 2018.11.22/1.md
gzc426 Nov 25, 2018
973f65e
Merge pull request #29 from zchoas/master
gzc426 Nov 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 2018.11.15/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions 2018.11.16/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
2 changes: 2 additions & 0 deletions 2018.11.17/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
12
1
2 changes: 2 additions & 0 deletions 2018.11.18/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
11
1
1 change: 1 addition & 0 deletions 2018.11.19/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11
1 change: 1 addition & 0 deletions 2018.11.20/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions 2018.11.21/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions 2018.11.22/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions 2018.11.25-leetcode80/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
5 changes: 0 additions & 5 deletions 2019.11.24/1.md

This file was deleted.

71 changes: 0 additions & 71 deletions 2019.11.24/2.md

This file was deleted.

22 changes: 22 additions & 0 deletions 2019.11.24/OCEAN_he95.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
public int maxProfit(int[] prices) {
int max = 0;
//如果只有一个元素,直接返回0
if(prices.length==1){
return 0;
}
//如果有两个元素,并且第二个比第一个大的话,返回第二个减去第一个的值
if(prices.length==2 && (prices[1]>prices[0])){
return prices[1]-prices[0];
}
//三个以上的元素就要考虑对于max的更新
for(int i=0;i<prices.length;i++){
for(int j=i+1;j<prices.length;j++){
if((prices[j]-prices[i])>max){
max = prices[j]- prices[i];
}
}
}
return max;
}
}
48 changes: 48 additions & 0 deletions 2019.11.24/kiritocly
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.zhongan;

import java.util.Scanner;

/**
* @author chenliyang
* @description 实现strStr()函数
* @date 2018/11/24
*/
public class Leetcode28 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String haystack = sc.next();
String needle = sc.next();
System.out.println(strStr(haystack, needle));
}

private static int strStr(String haystack, String needle) {
if (needle.length() == 0) {
//如果needle为空字符串则返回0
return 0;
}
char[] haystackCharArray = haystack.toCharArray();
char[] needleCharArray = needle.toCharArray();
for (int i = 0; i < haystackCharArray.length; i++) {
//遍历haystack,找到needle中的第一个字符在haystack中出现的位置的下标
if (haystackCharArray[i] == needleCharArray[0]) {
//比较needle中其他的字符是否与haystack对应位置匹配
int index = i + 1;
int j;
for (j = 1; index < haystackCharArray.length && j < needleCharArray.length; j++) {
if (haystackCharArray[index] == needleCharArray[j]) {
//字符串中字符匹配则比较下一个字符
index++;
} else {
break;
}
}
if (j == needleCharArray.length) {
//字符串全部匹配则返回needle字符串第一个字符在haystack中出现位置的下标
return i;
}
}
}
//未匹配则返回-1
return -1;
}
}
1 change: 1 addition & 0 deletions 2019.11.24/leeboolean
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TEST!!
14 changes: 14 additions & 0 deletions 2019.11.24/sourcema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# leetcode 80
public int removeDuplicates(int[] nums) {
if (nums == null || nums.length == 0 || nums.length < 3) {
return nums.length;
}
int i=0;
for (int j = 0; j < nums.length; j++) {
if (i < 2 || nums[j] != nums[i - 2]) {
nums[i] = nums[j];
i++;
}
}
return i;
}
1 change: 0 additions & 1 deletion 2019.11.24/testtest!

This file was deleted.

1 change: 1 addition & 0 deletions 2019.11.24/zzz.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 测试leetcode提交
105 changes: 76 additions & 29 deletions 2019.11.24/乔戈里.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,83 @@
```
import java.util.*;
public class Solution {
public String replaceSpace(StringBuffer str) {
String str1 = str.toString();
if(str1.equals(""))
return str1;
char [] strArray = str1.toCharArray();
int i =0;
int lengthSpace = 0;
while(i < strArray.length)
{
if(strArray[i] == ' ')
lengthSpace++;
i++;
}
int newStrLength = strArray.length + lengthSpace*2;
char [] newStr = new char[newStrLength];
int j = newStrLength-1;
i = strArray.length - 1;
while(i >= 0)
>考试结束,班级平均分只拿到了年级第二,班主任于是问道:大家都知道世界第一高峰珠穆朗玛峰,有人知道世界第二高峰是什么吗?正当班主任要继续发话,只听到角落默默想起来一个声音:”乔戈里峰”

### 前言

>2018.11.24号打卡
**今天的题目**leetcode80:
https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/description/

# 昨天的题解
### 题目

>每天一道leetcode28-移除元素
分类:双指针
中文链接:
https://leetcode.com/problems/implement-strstr/submissions/
英文链接
https://leetcode.com/problems/implement-strstr/submissions/

### 题目详述
>实现 strStr() 函数。
给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回 -1。
示例 1:
输入: haystack = "hello", needle = "ll"
输出: 2
示例 2:
输入: haystack = "aaaaa", needle = "bba"
输出: -1
说明:
当 needle 是空字符串时,我们应当返回什么值呢?这是一个在面试中很好的问题。
对于本题而言,当 needle 是空字符串时我们应当返回 0 。这与C语言的 strstr() 以及 Java的 indexOf() 定义相符。

###题目详解

>思路

- 一次比较过程:遍历haystack字符串,找到与needle开头字符然后记录下来这个位置i,然后j=i+1依次与needle进行比较,看每个字符是否相等,相等就继续比较下一个字符,直到找到不相等的字符,那么这次比较久结束,如果都相等直接返回i;
- 接下来就是haystack字符串i进行+1,然后再重复上述过程。

>代码

```java
class Solution {
public int strStr(String haystack, String needle) {
if(needle.length() == 0)
return 0;
char [] charArrayhaystack = haystack.toCharArray();
char [] charArrayneedle = needle.toCharArray();
for(int i =0;i<charArrayhaystack.length;i++)
{
if(strArray[i] != ' ')
if(charArrayhaystack[i] == charArrayneedle[0])
{
newStr[j--] = strArray[i--];
}else{
newStr[j--] = '0';
newStr[j--] = '2';
newStr[j--] = '%';
i--;
int j = i + 1;
int k = 1;
for(k=1;k<charArrayneedle.length && j < charArrayhaystack.length;k++)
{
if(charArrayhaystack[j] == charArrayneedle[k])
{
j++;
}else{
break;
}
}
if(k == charArrayneedle.length)
return i;
}
}
return new String(newStr);
return -1;
}
}
```

>代码讲解

- 5-6行把字符串转化成字符数组处理
- 7行是外层循环,也就是haystack字符串
- 9行如果haystack字符串的字符与needle字符串的开头字符相等,那么这里用j=i+1;然后从相等的下一个字符开始依次与needle的每一个字符进行比较
- 13-21行就是比较过程,18-19行如果中途出现不相等的那么就比较结束;跳到外层循环也就是haystack字符串再往下移动一位
- 22-23行就是needle字符串都遍历完了,k已经到了字符串的末尾的位置了,说明每个字符都相等,那么就返回haystack字符串开始的位置i;
### 结束语

2018.11.24号打卡

>作者乔戈里亲历2019秋招,哈工大计算机本硕,百度java工程师,欢迎大家关注我的**微信公众号:程序员乔戈里**,公众号有**3T编程资源**,以及我和我朋友(百度C++工程师)在秋招期间整理的近200M的面试必考的java与C++**面经**,并有**每天一道leetcode打卡群与技术交流群**,欢迎关注。
6 changes: 0 additions & 6 deletions 2019.11.24/变化.md

This file was deleted.

17 changes: 17 additions & 0 deletions 2019.11.24/句子.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```
class Solution {
public int removeElement(int[] nums, int val) {
int j=0;
for(int i=0;i<nums.length;++i)
{
if(nums[i]!=val)
{
nums[j]=nums[i];
++j;

}
}
return j;
}
}

27 changes: 27 additions & 0 deletions 2019.11.24/大魔王爱穿孖烟筒.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.util.ArrayList;
public class Solution {
public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
ListNode temp=listNode;
ArrayList<Integer> list=new ArrayList<>();
int count=0;
if(listNode==null)
return list;
while(temp!=null){
count++;
temp=temp.next;

}
int [] array=new int [count];
temp=listNode;
for(int i=0;i<count;i++){
array[i]= temp.val;
temp=temp.next;
}
while(count!=0){
list.add(array[count-1]);
count--;
}

return list;
}
}
23 changes: 23 additions & 0 deletions 2019.11.24/张小胖.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//暴力破解
class Solution {
public:
int strStr(string haystack, string needle) {
int m = haystack.size();
int n = needle.size();
if (!n) //是否为空
return 0;
for (int i = 0; i < m - n + 1; i++) {
int k = i, j = 0;
while (j < n) {
if (needle[j] == haystack[k]) {
j++;
k++; }
else
break;
}
if (j == n)
return i;
}
return -1;
}
};
1 change: 0 additions & 1 deletion 2019.11.24/微信名字.md

This file was deleted.

1 change: 1 addition & 0 deletions 2019.11.24/湛江甲鸟.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#时间是个伟大的作者,... 菜不是原罪,懒+怯 才是!
Loading