defsolution(A): # write your code in Python 2.7 first = A[0] last = sum(A) - A[0] N = len(A) min_diff = abs(first - last) for i in xrange(1, N - 1): num = A[i] first += num last -= num min_diff = min(abs(first - last), min_diff) return min_diff
defsolution(A, K): # write your code in Python 2.7 # N number of array A N = len(A) if (N == 0): return A K = K%N first = A[N-K:] last = A[:N-K] return first+last
defsolution(N): # write your code in Python 2.7 if (N > 2147483647or N < 1): return0 s = bin(N)[2:] last = s.__len__()-1 while (s[last] == '0'): last -= 1 s = s[0:last+1] count = 0 max = 0 for c in s: if (c == '0'): count += 1 if (count > max): max = count else: count = 0 returnmax