Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Mar 29th, 2020 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int sol(string s) {
  2.   int rhs = 0, lhs = 0;
  3.   for (int i = 0; i < s.size(); ++i) if (s[i] == 'A') ++rhs;
  4.   // rhs equals number of A's after index i [inclusive]
  5.   // lhs equals number of B's before index i [exclusive]
  6.   int ans = rhs;
  7.   for (int i = 0; i < s.size(); ++i) {
  8.     if (s[i] == 'A') --rhs;
  9.     else ++lhs;
  10.     ans = min(ans, rhs + lhs);
  11.   }
  12.   return ans;
  13. }
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