Skip to content

Commit c5cc7b7

Browse files
committed
remove package and change tab size to 2
1 parent b1e8102 commit c5cc7b7

File tree

4 files changed

+79
-87
lines changed

4 files changed

+79
-87
lines changed
Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1-
package com.andavid.leetcode._026;
1+
class Solution {
2+
public int removeDuplicates(int[] nums) {
3+
int len = nums.length;
4+
if (len <= 1) return len;
25

3-
public class Solution {
4-
public int removeDuplicates(int[] nums) {
5-
int len = nums.length;
6-
if (len <= 1) return len;
7-
8-
int tail = 1;
9-
for (int i = 1; i < len; i++) {
10-
if (nums[i] != nums[i - 1]) {
11-
nums[tail++] = nums[i];
12-
}
13-
}
14-
15-
return tail;
6+
int tail = 1;
7+
for (int i = 1; i < len; i++) {
8+
if (nums[i] != nums[i - 1]) {
9+
nums[tail++] = nums[i];
10+
}
1611
}
1712

18-
public static void main(String[] args) {
19-
Solution solution = new Solution();
20-
int[] nums = {1, 1, 2, 3, 3, 3};
13+
return tail;
14+
}
15+
16+
public static void main(String[] args) {
17+
Solution solution = new Solution();
18+
int[] nums = {1, 1, 2, 3, 3, 3};
2119

22-
int len = solution.removeDuplicates(nums);
23-
System.out.println("length = " + len);
20+
int len = solution.removeDuplicates(nums);
21+
System.out.println("length = " + len);
2422

25-
for (int i = 0; i < len; i++) {
26-
System.out.print(nums[i] + (i == len - 1 ? "" : ", "));
27-
}
23+
for (int i = 0; i < len; i++) {
24+
System.out.print(nums[i] + (i == len - 1 ? "" : ", "));
2825
}
26+
}
2927
}
Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
package com.andavid.leetcode._121;
2-
3-
public class Solution {
4-
public int maxProfit(int[] prices) {
5-
int max = 0;
6-
int min = Integer.MAX_VALUE;
7-
int len = prices.length;
8-
for (int i = 0; i < len; i++) {
9-
if (prices[i] < min) {
10-
min = prices[i];
11-
} else {
12-
int delta = prices[i] - min;
13-
if (delta > max) {
14-
max = delta;
15-
}
16-
}
1+
class Solution {
2+
public int maxProfit(int[] prices) {
3+
int max = 0;
4+
int min = Integer.MAX_VALUE;
5+
int len = prices.length;
6+
for (int i = 0; i < len; i++) {
7+
if (prices[i] < min) {
8+
min = prices[i];
9+
} else {
10+
int delta = prices[i] - min;
11+
if (delta > max) {
12+
max = delta;
1713
}
18-
return max;
14+
}
1915
}
16+
return max;
17+
}
2018

21-
public static void main(String[] args) {
22-
Solution solution = new Solution();
23-
int[] prices1 = {7, 1, 5, 3, 6, 4};
24-
int[] prices2 = {7, 6, 4, 3, 1};
25-
System.out.println(solution.maxProfit(prices1));
26-
System.out.println(solution.maxProfit(prices2));
27-
}
19+
public static void main(String[] args) {
20+
Solution solution = new Solution();
21+
int[] prices1 = {7, 1, 5, 3, 6, 4};
22+
int[] prices2 = {7, 6, 4, 3, 1};
23+
System.out.println(solution.maxProfit(prices1));
24+
System.out.println(solution.maxProfit(prices2));
25+
}
2826
}
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
package com.andavid.leetcode._122;
2-
3-
public class Solution {
4-
public int maxProfit(int[] prices) {
5-
int maxProfit = 0;
6-
int len = prices.length;
7-
for (int i = 1; i < len; i++) {
8-
if (prices[i] > prices[i - 1]) {
9-
maxProfit += prices[i] - prices[i - 1];
10-
}
11-
}
12-
return maxProfit;
1+
class Solution {
2+
public int maxProfit(int[] prices) {
3+
int maxProfit = 0;
4+
int len = prices.length;
5+
for (int i = 1; i < len; i++) {
6+
if (prices[i] > prices[i - 1]) {
7+
maxProfit += prices[i] - prices[i - 1];
8+
}
139
}
10+
return maxProfit;
11+
}
1412

15-
public static void main(String[] args) {
16-
Solution solution = new Solution();
17-
System.out.println(solution.maxProfit(new int[]{7, 1, 5, 3, 6, 4}));
18-
System.out.println(solution.maxProfit(new int[]{7, 6, 4, 3, 1}));
19-
}
13+
public static void main(String[] args) {
14+
Solution solution = new Solution();
15+
System.out.println(solution.maxProfit(new int[]{7, 1, 5, 3, 6, 4}));
16+
System.out.println(solution.maxProfit(new int[]{7, 6, 4, 3, 1}));
17+
}
2018
}
Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1-
package com.andavid.leetcode._189;
1+
class Solution {
2+
public void rotate(int[] nums, int k) {
3+
int n = nums.length;
4+
k %= n;
5+
reverse(nums, 0, n - k - 1);
6+
reverse(nums, n - k, n - 1);
7+
reverse(nums, 0, n - 1);
8+
}
29

3-
public class Solution {
4-
public void rotate(int[] nums, int k) {
5-
int n = nums.length;
6-
k %= n;
7-
reverse(nums, 0, n - k - 1);
8-
reverse(nums, n - k, n - 1);
9-
reverse(nums, 0, n - 1);
10+
private void reverse(int[] nums, int from, int to) {
11+
while (from < to) {
12+
int temp = nums[from];
13+
nums[from++] = nums[to];
14+
nums[to--] = temp;
1015
}
16+
}
1117

12-
private void reverse(int[] nums, int from, int to) {
13-
while (from < to) {
14-
int temp = nums[from];
15-
nums[from++] = nums[to];
16-
nums[to--] = temp;
17-
}
18-
}
19-
20-
public static void main(String[] args) {
21-
Solution solution = new Solution();
22-
int[] nums = {1, 2, 3, 4, 5, 6, 7};
23-
solution.rotate(nums, 3);
24-
int len = nums.length;
25-
for (int i = 0; i < len; i++) {
26-
System.out.print(nums[i] + (i == len - 1 ? "" : ", "));
27-
}
18+
public static void main(String[] args) {
19+
Solution solution = new Solution();
20+
int[] nums = {1, 2, 3, 4, 5, 6, 7};
21+
solution.rotate(nums, 3);
22+
int len = nums.length;
23+
for (int i = 0; i < len; i++) {
24+
System.out.print(nums[i] + (i == len - 1 ? "" : ", "));
2825
}
26+
}
2927
}

0 commit comments

Comments
 (0)