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
sortByValue: (data)-> | |
z = [] | |
for k,v of data | |
z.push([v, k]) | |
z.sort((a, b)-> | |
if a[0] < b[0] | |
return -1 | |
if a[0] > b[0] | |
return 1 | |
return 0 |
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
sortByValue:(data, reverse)-> | |
z = [] | |
for k,v of data | |
z.push([v, k]) | |
z.sort((a, b)-> | |
if a[0] < b[0] | |
return -1 | |
if a[0] > b[0] | |
return 1 |
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
def quickSort(data, left, right): | |
index = partition(data, left, right) | |
if left < index - 1: | |
quickSort(data, left, index - 1) | |
if index < right: | |
quickSort(data, index, right) | |
def partition(data, left, right): | |
pivot = data[(left + right) / 2] | |
while left < right: |
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 Solve: | |
ans = [] | |
def __init__(self,n,m,k,data): | |
self.n = n | |
self.m = m | |
if k == 1: | |
data = [[dd * -1 for dd in d] for d in data] | |
for g in xrange(self.n): | |
self.quickSort(data, g, 0, self.m-1) | |
print len(self.ans) |
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
def solve(n,m,k,data): | |
ans = [] | |
if k == 1: | |
data = [[dd * -1 for dd in d] for d in data] | |
for i in xrange(n): | |
isSorted = False | |
while not isSorted: | |
swapCnt = 0 | |
for j in xrange(m - 1): |
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 AlienAndGame: | |
def getNumber(self, board): | |
arr = [] | |
for r in board: | |
arr.append(list(r)) | |
rlen = len(arr) | |
clen = len(arr[0]) | |
N = min(rlen, clen) |
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 ClusteringObj | |
constructor: (@coordinate, @clusterId)-> | |
class @Centroid | |
constructor: (keys)-> | |
@num = 0 | |
@coordinate = {} | |
for k in keys | |
@coordinate[k] = 0 |
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
def prime_decomposition(n): | |
i = 2 | |
table = [] | |
while i * i <= n: | |
while n % i == 0: | |
n /= i | |
table.append(i) | |
i += 1 | |
if n > 1: | |
table.append(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
def is_prime(n): | |
i = 2 | |
while i * i <=n: | |
if n % i == 0: | |
return False | |
i += 1 | |
return True |
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
def prime_table(n): | |
list = [True for _ in xrange(n + 1)] | |
i = 2 | |
while i * i <= n: | |
if list[i]: | |
j = i + i | |
while j <= n: | |
list[j] = False | |
j += i | |
i += 1 |