Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 9th, 2020 167 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. bool isSubSum (int arr[], int n, int sum) {
  2.     int curr_sum = arr[0], s = 0;
  3.    
  4.     for (int e = 1; e <= n; e++) {
  5.         while (curr_sum > sum && s < e-1) {
  6.             curr_sum -= arr[s];
  7.             s++;
  8.         }
  9.        
  10.         if (curr_sum == sum) {
  11.             return true;
  12.         }
  13.        
  14.         if (e < n) {
  15.             curr_sum = arr[e];
  16.         }
  17.     }
  18.    
  19.     return (curr_sum == sum ? true : false);
  20. }
  21.  
  22. int main() {
  23.     int arr[]{7,8,2,4,5};
  24.     cout<<isSubSum(arr, 5, 9);
  25.     return 0;
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top