Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit385d25f

Browse files
refactor 638
1 parent4a14e9f commit385d25f

File tree

1 file changed

+30
-26
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+30
-26
lines changed

‎src/main/java/com/fishercoder/solutions/_638.java

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,40 @@
4141
You are not allowed to buy more items than you want, even if that would lower the overall price.
4242
*/
4343
publicclass_638 {
44-
/**reference: https://leetcode.com/articles/shopping-offers/#approach-1-using-recursion-accepted*/
45-
publicintshoppingOffers(List<Integer>price,List<List<Integer>>special,List<Integer>needs) {
46-
returnshopping(price,special,needs,0);
47-
}
48-
49-
publicintshopping(List<Integer>price,List<List<Integer>>special,List<Integer>needs,inti) {
50-
if (i ==special.size()) {
51-
returndot(needs,price);
44+
publicstaticclassSolution1 {
45+
/**
46+
* reference: https://leetcode.com/articles/shopping-offers/#approach-1-using-recursion-accepted
47+
*/
48+
publicintshoppingOffers(List<Integer>price,List<List<Integer>>special,List<Integer>needs) {
49+
returnshopping(price,special,needs,0);
5250
}
53-
ArrayList<Integer>clone =newArrayList(needs);
54-
intj =0;
55-
for (j =0;j <special.get(i).size() -1;j++) {
56-
intdiff =clone.get(j) -special.get(i).get(j);
57-
if (diff <0) {
58-
break;
51+
52+
publicintshopping(List<Integer>price,List<List<Integer>>special,List<Integer>needs,inti) {
53+
if (i ==special.size()) {
54+
returndot(needs,price);
55+
}
56+
ArrayList<Integer>clone =newArrayList(needs);
57+
intj =0;
58+
for (j =0;j <special.get(i).size() -1;j++) {
59+
intdiff =clone.get(j) -special.get(i).get(j);
60+
if (diff <0) {
61+
break;
62+
}
63+
clone.set(j,diff);
64+
}
65+
if (j ==special.get(i).size() -1) {
66+
returnMath.min(special.get(i).get(j) +shopping(price,special,clone,i),shopping(price,special,needs,i +1));
67+
}else {
68+
returnshopping(price,special,needs,i +1);
5969
}
60-
clone.set(j,diff);
61-
}
62-
if (j ==special.get(i).size() -1) {
63-
returnMath.min(special.get(i).get(j) +shopping(price,special,clone,i),shopping(price,special,needs,i +1));
64-
}else {
65-
returnshopping(price,special,needs,i +1);
6670
}
67-
}
6871

69-
publicintdot(List<Integer>a,List<Integer>b) {
70-
intsum =0;
71-
for (inti =0;i <a.size();i++) {
72-
sum +=a.get(i) *b.get(i);
72+
publicintdot(List<Integer>a,List<Integer>b) {
73+
intsum =0;
74+
for (inti =0;i <a.size();i++) {
75+
sum +=a.get(i) *b.get(i);
76+
}
77+
returnsum;
7378
}
74-
returnsum;
7579
}
7680
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp