Skip to content

Commit 18e17bc

Browse files
authored
Merge pull request gzc426#6 from gzc426/master
更新
2 parents a161756 + 1a09a80 commit 18e17bc

File tree

181 files changed

+6502
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+6502
-1
lines changed

018429.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
int firstUniqChar(char* s) {
2+
int ascii[256]={0};
3+
int i=0,len;
4+
while(s[i]!='\0')
5+
{
6+
i++;
7+
}
8+
len=i;
9+
for(i=0;i<len;i++)
10+
{
11+
ascii[s[i]]++;
12+
}
13+
i=0;
14+
while(ascii[s[i]]!=1&&i<len) i++;
15+
if(i==len)
16+
return -1;
17+
return i;
18+
}

2018.11.18/大腩肚.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
public List<List<Integer>> threeSum(int[] nums) {
2+
final int length = nums.length;
3+
List<List<Integer>> result = new ArrayList<>();
4+
HashMap<Integer, int[]> hashMap = new HashMap<Integer, int[]>();
5+
6+
if (length < 3) return result;
7+
8+
Arrays.sort(nums);
9+
10+
for (int i = 0; i < length - 2; i++) {
11+
hashMap.clear();
12+
13+
if (i == 0 || nums[i] > nums[i - 1]) {
14+
for (int j = i + 1; j < length; j++) {
15+
16+
if (hashMap.containsKey(nums[j])) {
17+
ArrayList<Integer> elem = new ArrayList<Integer>(3);
18+
19+
elem.add(hashMap.get(nums[j])[0]);
20+
elem.add(hashMap.get(nums[j])[1]);
21+
elem.add(nums[j]);
22+
23+
result.add(elem);
24+
25+
while (j < (length - 1) && nums[j] == nums[j + 1]) j++;
26+
} else {
27+
int[] temp = new int[2];
28+
temp[0] = nums[i];
29+
temp[1] = nums[j];
30+
hashMap.put(0 - (nums[i] + nums[j]), temp);
31+
}
32+
}
33+
}
34+
}
35+
return result;
36+
}

2018.11.25-leetcode80/大魔王爱穿孖烟筒.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
```
12
class Solution {
23
public int removeDuplicates(int[] nums) {
34
int count=0;
@@ -41,3 +42,4 @@ class Solution {
4142
return count;
4243
}
4344
}
45+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
```
2+
class Solution {
3+
public int maxArea(int[] height) {
4+
int left=0;//从左边遍历
5+
int right=height.length-1;//从右边遍历
6+
int tempCha=0;
7+
int sum=0;
8+
int tempsum=0;
9+
while(left<right){//遍历到中间,两指针重合为止,求出沿途的面积。
10+
tempCha=right-left;//每次遍历记录临时长度差,也就是底边的长度
11+
if(height[right]>height[left]){
12+
tempsum=height[left]*tempCha; //短(短板)的边作为高,求出此时的面积
13+
left++;
14+
}else{
15+
tempsum=height[right]*tempCha;
16+
right--;
17+
}
18+
if(tempsum>sum){
19+
sum=tempsum;
20+
}
21+
22+
23+
}
24+
return sum;
25+
}
26+
}
27+
```

2018.11.27-leetcode125/。。。.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
```
12
public boolean isPalindrome(String s){
23
if (s.length() >= 2){
34
int left = 0,right = s.length()-1;
@@ -26,3 +27,4 @@ public boolean isPalindrome(String s){
2627
}
2728
return true;
2829
}
30+
```
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
```
2+
class Solution {
3+
public boolean isPalindrome(String s) {
4+
s = s.toLowerCase();
5+
char [] charArray = s.toCharArray();
6+
7+
int begin = 0;
8+
int end = charArray.length - 1;
9+
while(begin < end)
10+
11+
{
12+
if (!isChar(charArray[begin])){//不是数字和小字母
13+
begin++;
14+
continue;
15+
}
16+
if (!isChar(charArray[end])){//不是数字和小字母
17+
end--;
18+
continue;
19+
}
20+
if(charArray[begin] == charArray[end])
21+
{
22+
begin++;
23+
end--;
24+
}else{
25+
return false;
26+
}
27+
}
28+
return true;
29+
}
30+
public boolean isChar(char c){//判断是否为数字或者字母
31+
if (c<48||(c>57&&c<65)||(c>90&&c<97)||c>122){
32+
return false;
33+
}
34+
return true;
35+
}
36+
}
37+
```

2018.11.27-leetcode125/暮成雪.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution {
2+
public boolean isPalindrome(String s) {
3+
4+
s = s.replaceAll("[^a-zA-Z]", "").toLowerCase();
5+
s = s.toLowerCase();
6+
char [] charArray = s.toCharArray();
7+
String temp = "";
8+
for(int i=0;i<charArray.length;i++)
9+
{
10+
if( ((int)charArray[i] >= 48 && (int)charArray[i] <= 57) || ((int)charArray[i] >= 97 && (int)charArray[i] <= 122))
11+
{
12+
temp += charArray[i];
13+
}
14+
}
15+
char [] resultArray = temp.toCharArray();
16+
int begin = 0;int end = resultArray.length - 1;
17+
while(begin < end)
18+
{
19+
if(resultArray[begin] == resultArray[end])
20+
{
21+
begin++;
22+
end--;
23+
}else{
24+
return false;
25+
}
26+
}
27+
return true;
28+
}
29+
}

2018.11.28-leetcode151/018429.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
int top=0;
2+
void push(char c,char* stack)
3+
{
4+
stack[top++]=c;
5+
}
6+
char pop(char* stack)
7+
{
8+
return stack[--top];//写入s1
9+
}
10+
void reverseWords(char *s) {
11+
int i=0,j=0,flag=0;
12+
while(s[i]!='\0') i++;
13+
char* stack = (char*)malloc(i);
14+
char* s1 = (char*)malloc(i+1);
15+
i--;
16+
while(i>=0)
17+
{
18+
if(s[i]==' ')
19+
{
20+
while(top!=0)//如果栈不为空
21+
{
22+
flag=1;
23+
s1[j++]=pop(stack);
24+
}
25+
if(flag==1)
26+
{
27+
s1[j++]=' ';
28+
flag=0;//重置flag
29+
}
30+
i--;
31+
}
32+
else
33+
{
34+
push(s[i--],stack);
35+
}
36+
}
37+
if(s[++i]!=' ')
38+
{
39+
while(top!=0)//如果栈不为空
40+
s1[j++]=pop(stack);
41+
s[j]=' ';
42+
}
43+
else
44+
j--;
45+
s1[j]='\0';
46+
s = strcpy(s,s1);
47+
free(s1);
48+
}

2018.11.28-leetcode151/。。。.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
```
12
public String reverseWords(String s) {
23
int i = s.length()-1,wordRight=-1;
34
StringBuilder builder = new StringBuilder();
@@ -25,3 +26,4 @@ public String reverseWords(String s) {
2526
}
2627
return builder.toString();
2728
}
29+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
```
2+
public class Solution {
3+
public String reverseWords(String s) {
4+
if (s == null || s.length() == 0) {
5+
return "";
6+
}
7+
String[] array = s.split(" ");//按照空格划分字符串
8+
String str = "";
9+
for (int i = array.length - 1; i >= 0; i--) {
10+
if (!array[i].equals("")) {
11+
if (str.length() > 0) {
12+
str += " ";
13+
}
14+
str += array[i];//如果不是空字符串,就把截断的旧字符串添加到新字符串中。
15+
}
16+
}
17+
return str;
18+
}
19+
}
20+
```

0 commit comments

Comments
 (0)