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
| class LittleElephantAndBallsAgain: | |
| def getNumber(self, S): | |
| c = S[0] | |
| longest = 0 | |
| l = 1 | |
| for s in S[1::]: | |
| if s != c: | |
| longest = max(longest, l) | |
| l = 1 | |
| c = 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
| class LittleElephantAndIntervalsDiv2: | |
| def getNumber(self, M, L, R): | |
| s = set() | |
| count = 0 | |
| for i in reversed(xrange(0, len(L))): | |
| is_paint = False | |
| for n in range(L[i], R[i]+1): | |
| if n not in s: | |
| is_paint = True | |
| s.add(n) |
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
| import itertools | |
| class GUMIAndSongsDiv2: | |
| def maxSongs(self, duration, tone, T): | |
| duration_tones = [] | |
| for i, d in enumerate(duration): | |
| duration_tones.append((tone[i], d)) | |
| duration_tones.sort() |
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
| class ArcadeManao: | |
| def shortestLadder(self, level, coinRow, coinColumn): | |
| self.level = level | |
| self.goal = (coinRow - 1, coinColumn - 1) | |
| N = len(level) - 1 | |
| M = len(level[0]) - 1 | |
| print ((N, M), level[N][M]) | |
| for ladder_len in xrange(0, N+1): | |
| print ('--start--', ladder_len) |
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
| class ArcadeManao: | |
| def shortestLadder(self, level, coinRow, coinColumn): | |
| self.level = level | |
| self.goal = (coinRow - 1, coinColumn - 1) | |
| print self.goal | |
| self.R = len(level) | |
| self.C = len(level[0]) | |
| queue = [] | |
| visited = set() |
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
| print 1 << n |
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
| import Queue | |
| class ArcadeManao: | |
| def shortestLadder(self, level, coinRow, coinColumn): | |
| goal = (coinRow - 1, coinColumn - 1) | |
| R = len(level) | |
| C = len(level[0]) | |
| #priority queue (max ladder, current ladder, r, c) | |
| p_queue = Queue.PriorityQueue() |
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
| class ColorfulRoad: | |
| DEFAULT = 1000000 | |
| def getMin(self, road): | |
| memo = [-1 for i in xrange(len(road))] | |
| ans = self.f(road, 0, memo) | |
| if ans < self.DEFAULT: | |
| return ans | |
| return -1 | |
| def f(self, road, n, memo): |
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
| class TheNumberGameDivTwo: | |
| def find(self, n): | |
| if self.rec(n): | |
| return 'John' | |
| return 'Brus' | |
| def rec(self, n, memo={}): | |
| if n in memo: | |
| return memo[n] | |
| memo[n] = self.d(n) |
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
| class TravelOnMars2: | |
| def minTimes(self, range, startCity, endCity): | |
| N = len(range) | |
| INF = 1000000 | |
| dp = [[INF for _ in xrange(N)] for _ in xrange(N)] | |
| for i in xrange(N): | |
| for j in xrange(N): | |
| l = (i - j + N) % N | |
| r = (j - i + N) % N | |
| if min(l, r) <= range[i]: |