fork download
  1. class Solution {
  2. public:
  3. int coinChange(vector<int>& coins, int amount) {
  4.  
  5. int *dp = new int[amount+1];
  6.  
  7. dp[0] = 0;
  8.  
  9. for(int i=1;i<=amount;i++){
  10. int x = INT_MAX;
  11. for(int j=0;j<coins.size();j++){
  12.  
  13. if(coins[j] > i){
  14. continue;
  15. }
  16.  
  17. x = min(dp[i-coins[j]], x); // dp[7-1], dp[7-3], dp[4], dp[0]
  18. }
  19.  
  20. if(x == INT_MAX){
  21. dp[i] = INT_MAX;
  22. }
  23. else{
  24. dp[i] = x +1;
  25. }
  26.  
  27.  
  28. }
  29.  
  30. if(dp[amount] == INT_MAX){
  31. return -1;
  32. }
  33. return dp[amount];
  34.  
  35.  
  36. }
  37. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:20: error: ‘vector’ has not been declared
     int coinChange(vector<int>& coins, int amount) {
                    ^~~~~~
prog.cpp:3:26: error: expected ‘,’ or ‘...’ before ‘<’ token
     int coinChange(vector<int>& coins, int amount) {
                          ^
prog.cpp: In member function ‘int Solution::coinChange(int)’:
prog.cpp:5:27: error: ‘amount’ was not declared in this scope
         int *dp = new int[amount+1];
                           ^~~~~~
prog.cpp:10:21: error: ‘INT_MAX’ was not declared in this scope
             int x = INT_MAX;
                     ^~~~~~~
prog.cpp:10:21: note: ‘INT_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’?
prog.cpp:1:1:
+#include <climits>
 class Solution {
prog.cpp:10:21:
             int x = INT_MAX;
                     ^~~~~~~
prog.cpp:11:27: error: ‘coins’ was not declared in this scope
             for(int j=0;j<coins.size();j++){
                           ^~~~~
prog.cpp:17:21: error: ‘min’ was not declared in this scope
                 x = min(dp[i-coins[j]], x); // dp[7-1], dp[7-3], dp[4], dp[0]
                     ^~~
prog.cpp:30:26: error: ‘INT_MAX’ was not declared in this scope
         if(dp[amount] == INT_MAX){
                          ^~~~~~~
prog.cpp:30:26: note: ‘INT_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’?
stdout
Standard output is empty