This file contains 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 math | |
def index(list1, n): | |
startIndex = 0 | |
endIndex = len(list1) - 1 | |
while startIndex <= endIndex: | |
mid = startIndex + int(math.floor((endIndex-startIndex)/2)) | |
if list1[mid] == n: | |
print n | |
print mid |
This file contains 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 Solution(object): | |
def lengthOfLongestSubstringTwoDistinct(self, s): | |
""" | |
:type s: str | |
:rtype: int | |
""" | |
sublen = 1 | |
substrings = [] | |
result = {} | |
for i in range(0,len(s)+1): |
This file contains 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
#Kth rank value | |
scores = [10,20,12,3,8] | |
scores.sort() | |
rank_scores = {} | |
for i,val in enumerate(scores): | |
rank_scores[i+1] = val | |
print rank_scores[3] |
This file contains 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 palindrom(string1): | |
i = 0 | |
j = len(string1) -1 | |
flag = True | |
while i<len(string1)-1 and j >=0: | |
if string1[i] != string1[j]: | |
flag = False | |
break | |
else: |
This file contains 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
Str1 = "aaabbcgfhh" | |
SubStrs = [] | |
SubStrd_Dict = {} | |
for i in range(1,len(Str1)): | |
#SubStrs.append(i) | |
SubStrs = [] | |
for j in range(0,len(Str1)-i): | |
SubStrs.append(Str1[j:j+i]) | |
#print SubStrs | |
SubStrd_Dict[i] = SubStrs |
NewerOlder