Created
June 18, 2012 17:41
-
-
Save aakashns/2949629 to your computer and use it in GitHub Desktop.
Code snippet for 1's and 0's
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int diff = 0; | |
for (int i = 0; i <= n; i++){ | |
if (B[diff + n] == -1) B[diff + n] = i; | |
else B[diff+ n] = min(B[diff + n], i); | |
if (C[diff + n] == -1) C[diff + n] = i; | |
else C[diff + n] = max(C[diff + n], i); | |
if (i < n && A[i] == 0) diff--; | |
else diff++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment