File tree 2 files changed +32
-1
lines changed
src/main/java/org/wcong/algorithm/epi/honors
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,10 @@ how to solve a problem
4
4
| step| describe|
5
5
| ---| ---|
6
6
| Concrete examples| Manually solve concrete instances of the problem and then build a general solution.|
7
+ | Graph modeling| Describe the problem using a graph and solve it using an existing algorithm.|
7
8
| Case analysis| Split the input/execution into a number of cases and solve each case in isolation.|
8
9
| Iterative refinement| Most problems can be solved using a brute-force approach. Find such a solution and improve upon it.|
9
10
| Reduction| Use a well-known solution to some other problem as a subroutine.|
10
- | Graph modeling| Describe the problem using a graph and solve it using an existing algorithm.|
11
11
12
12
### data structure
13
13
#### primitive
Original file line number Diff line number Diff line change
1
+ package org .wcong .algorithm .epi .honors ;
2
+
3
+ /**
4
+ * Write a program to compute the maximum profit
5
+ * that can be made by buying and selling a share k times over a given day range.
6
+ * Your program takes k and an array of daily stock prices as input.
7
+ *
8
+ * @author wcong<wc19920415@gmail.com>
9
+ * @since 12/03/2018
10
+ */
11
+ public class BuySellStockKTimes {
12
+
13
+ static class Info {
14
+ int times ;
15
+ int profit ;
16
+ }
17
+
18
+ public int maxProfit (int [] array , int k ) {
19
+ Info [] infos = new Info [array .length ];
20
+ infos [0 ] = new Info ();
21
+ for (int i = 1 ; i < array .length ; i ++) {
22
+ for (int j = 0 ; j < i ; j ++) {
23
+ if (array [j ] < array [i ]) {
24
+
25
+ }
26
+ }
27
+ }
28
+ return 0 ;
29
+ }
30
+
31
+ }
You can’t perform that action at this time.
0 commit comments