Skip to content

Commit de02576

Browse files
author
Cenkay
committed
Initial commit
0 parents  commit de02576

File tree

1,165 files changed

+17817
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,165 files changed

+17817
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Cenkay Arapisaoglu
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 1196 additions & 0 deletions
Large diffs are not rendered by default.

solutions/python/160.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution(object):
2+
def getIntersectionNode(self, headA, headB):
3+
r1, r2, l1, l2 = headA, headB, 0, 0
4+
while headA: headA, l1 = headA.next, l1 + 1
5+
while headB: headB, l2 = headB.next, l2 + 1
6+
while l1 > l2: r1, l1 = r1.next, l1 - 1
7+
while l2 > l1: r2, l2 = r2.next, l2 - 1
8+
while r1 != r2: r1, r2 = r1.next, r2.next
9+
return r1

solutions/python/190.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Solution:
2+
# @param n, an integer
3+
# @return an integer
4+
def reverseBits(self, n):
5+
return int(bin(n)[2:].zfill(32)[::-1],2)

solutions/python/271.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Codec:
2+
3+
def encode(self, strs):
4+
return "".join(str(len(s)) + ":" + s for s in strs)
5+
6+
def decode(self, s):
7+
strs = []
8+
while s:
9+
i = s.find(":")
10+
length = int(s[:i])
11+
s = s[i+1:]
12+
strs.append(s[:length])
13+
s = s[length:]
14+
return strs

solutions/python/277.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# The knows API is already defined for you.
2+
# @param a, person a
3+
# @param b, person b
4+
# @return a boolean, whether a knows b
5+
# def knows(a, b):
6+
7+
class Solution(object):
8+
def findCelebrity(self, n):
9+
i = 0
10+
while i < n:
11+
person = i
12+
i += 1
13+
while i < n and not knows(person, i) and knows(i, person):
14+
i += 1
15+
j = person - 1
16+
while j >= 0 and not knows(person, j) and knows(j, person):
17+
j -= 1
18+
return person if j < 0 else -1

solutions/python/281.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class ZigzagIterator(object):
2+
3+
def __init__(self, v1, v2):
4+
self.arr1, self.arr2, self.l1, self.l2 = v1, v2, len(v1), len(v2)
5+
self.i = self.j = 0
6+
self.n, self.turn = max(self.l1, self.l2), v1 and 1 or 0
7+
8+
def next(self):
9+
if self.turn:
10+
num = self.arr1[self.i]
11+
self.i += 1
12+
if self.j < self.l2:
13+
self.turn = 0
14+
else:
15+
num = self.arr2[self.j]
16+
self.j += 1
17+
if self.i < self.l1:
18+
self.turn = 1
19+
return num
20+
21+
def hasNext(self):
22+
return self.turn and self.i < self.l1 or self.j < self.l2

solutions/python/374.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution(object):
2+
def guessNumber(self, n):
3+
l, r, g = 1, n, 1
4+
while g and l <= r:
5+
m = (l + r) // 2
6+
g = guess(m)
7+
if g == 1:
8+
l = m + 1
9+
else:
10+
r = m
11+
return m

solutions/python/400.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution(object):
2+
def findNthDigit(self, n):
3+
start, size, step = 1, 1, 9
4+
while n > size * step:
5+
n, size, step, start = n - (size * step), size + 1, step * 10, start * 10
6+
return int(str(start + (n - 1) // size)[(n - 1) % size])

solutions/python/423.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution(object):
2+
def originalDigits(self, s):
3+
res = ""
4+
res += "0"*s.count('z')
5+
res += "1"*(s.count('o')-s.count('z')-s.count('w')-s.count('u'))
6+
res += "2"*s.count('w')
7+
res += "3"*(s.count('h') - s.count('g'))
8+
res += "4"*s.count('u')
9+
res += "5"*(s.count('f') - s.count('u'))
10+
res += "6"*s.count('x')
11+
res += "7"*(s.count('s')-s.count('x'))
12+
res += "8"*s.count("g")
13+
res += "9"*(s.count('i') - s.count('x') - s.count("g") - s.count('f') + s.count('u'))
14+
return res

0 commit comments

Comments
 (0)