Skip to content

Commit fae15a9

Browse files
committed
feature: new start
1 parent 0c937b7 commit fae15a9

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

code/source/maxSubArray.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class maxSubArray {
2+
3+
public static int maxSubArray(int[] nums) {
4+
int max = Integer.MIN_VALUE;
5+
int sum;
6+
for (int i = 0; i < nums.length; i++) {
7+
sum = 0;
8+
for (int j = i; j < nums.length; j++) {
9+
sum += nums[j];
10+
if (sum > max) {
11+
max = sum;
12+
}
13+
}
14+
}
15+
return max;
16+
}
17+
18+
public static void main(String[] args) {
19+
int[] data = new int[]{-2, 1, -3, 4, -1, 2, 1, -5, 4};
20+
System.out.println(maxSubArray(data));
21+
}
22+
}

code/8月/1.java renamed to code/source/twoSum.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import java.util.HashMap;
22
import java.util.Map;
33

4-
class Solution {
4+
class twoSum {
55

66
public static int[] twoSum(int[] nums, int target) throws Exception {
77
Map<Integer, Integer> map = new HashMap<>();

write/8月/1.两数之和.md renamed to solution/leetcode/1.两数之和.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# 1. 两数之和
22

3+
## 日期
4+
5+
2018-11-01
6+
37
## 题目描述
48

59
给定一个整数数组和一个目标值,找出数组中和为目标值的两个数。
@@ -15,6 +19,10 @@
1519
所以返回 [0, 1]
1620
```
1721

22+
## 想法
23+
24+
直接使用 HashMap
25+
1826
## My
1927

2028
```
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# 53. 最大子序和
2+
3+
## 日期
4+
5+
2018-11-01
6+
7+
## 题目描述
8+
9+
给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。
10+
11+
示例:
12+
13+
```
14+
输入: [-2,1,-3,4,-1,2,1,-5,4],
15+
输出: 6
16+
解释: 连续子数组 [4,-1,2,1] 的和最大,为 6。
17+
```
18+
19+
进阶:
20+
21+
如果你已经实现复杂度为 O(n) 的解法,尝试使用更为精妙的分治法求解。
22+
23+
## 思路
24+
25+
暴力计算出所有连续加值。
26+
27+
## My
28+
29+
```
30+
public static int maxSubArray(int[] nums) {
31+
int max = Integer.MIN_VALUE;
32+
int sum;
33+
for (int i = 0; i < nums.length; i++) {
34+
sum = 0;
35+
for (int j = i; j < nums.length; j++) {
36+
sum += nums[j];
37+
if (sum > max) {
38+
max = sum;
39+
}
40+
}
41+
}
42+
return max;
43+
}
44+
```

0 commit comments

Comments
 (0)