Method
isPartition
(int j, String i2, int i, int curSum)
Source from the content-addressed store, hash-verified
| 1 | //plain recursion |
| 2 | class Solution { |
| 3 | public boolean isPartition(int j, String i2, int i, int curSum){ |
| 4 | int n = i2.length(); |
| 5 | // base case |
| 6 | if(j == n){ |
| 7 | return (curSum == i); |
| 8 | } |
| 9 | for(int index=j;index<n;index++){ |
| 10 | int val = Integer.parseInt(i2.substring(j,index+1)); |
| 11 | if(isPartition(index+1,i2,i,curSum+val)){ |
| 12 | return true; |
| 13 | } |
| 14 | } |
| 15 | return false; |
| 16 | } |
| 17 | public int punishmentNumber(int n) { |
| 18 | int res=0; |
| 19 | for(int i=1;i<=n;i++){ |
Tested by
no test coverage detected