Raymend
BAN USERHere is my Python solution:
class Solution():
def occur(self, d, num):
s = [str(x) for x in list(range(1, num + 1))]
tmp = "".join(s)
return tmp.count(str(d))
def pageBounds(self, d, k):
if d ==1 and k == 0:
return (0,0)
lower = 0
upper = 40000
found = False
i = 1
while not found:
if self.occur(d, i) < k:
i += 1
elif self.occur(d, i) == k:
lower = i
found = True
for i in range(lower, 40000):
if self.occur(d, i) == k+1:
upper = i-1
break
return (lower, upper)
I tried a python code, check here
def checkPalindrome(inputString = ""):
if inputString[::-1] == inputString:
return True
else:
return False
strings = "abcdefeabc"
for i in range(len(strings)):
for j in range(i+1, len(strings)):
if strings[i] == strings[j]:
if checkPalindrome(strings[i:j+1]):
print strings[i:j+1]
#python
def new_array(array, index):
a = array
i = index
f = 1
b = 1
if i >=0:
# O(n)
for p in range(i):
f *= a[p]
for q in range(i+1, len(a)):
b *= a[q]
print f, b
return f * b
arr = [1,2,3,4,5]
new_arr = []
# O(n)
for m in range(len(arr)):
new_arr.append(new_array(arr, m))
print new_arr
And one more thing, you should think about the size of this kind of multiplication. It may not work for even a little large number. For example, array with size of 20 and full of 20s.
- Raymend August 30, 2013
Could it convert to a data structure like a tree.
- Raymend February 12, 2015