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 getIndex(x, y, width): | |
return x + y * width | |
def printMatrix(matrix, m, n): | |
""" | |
Print Matrix row by row | |
""" | |
for i in range(m*n): | |
print(matrix[i], end="\t") | |
if((i + 1) % n == 0): |
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 getIndex(x, y, width): | |
""" | |
Return the index in 1D array | |
""" | |
index = x + y * width | |
return index | |
def printMatrix(matrix, width): | |
""" | |
Print Matrix row by row |
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 stringCompression(originalString): | |
"""Compress string by using the counts of repeated characters | |
Input: aabcccccaaa | |
Output: a2b1c5a3 | |
If the length of string bigger than the compressed string | |
Then return the original string | |
""" | |
if(originalString == ""): | |
return originalString |
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 replaceSpace(string): | |
"""Replace all spaces in a string with '%20'""" | |
"Split string by space, save into a list" | |
newList = string.split() | |
"str.join concatenate list at the end" | |
newString = "%20".join(newList) | |
return newString |
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 permutationString(firstStr, secondStr): | |
"Return True if the second string is a permutation of the other" | |
"""If the length of two strings are different, | |
directly return false | |
""" | |
if(len(firstStr) != len(secondStr)): | |
return False | |
"Change all characters to lowercase" |
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
#include <stdio.h> | |
void swap(char* a, char* b); | |
void reverse(char* str); | |
int main(){ | |
char strArray[] = "1point3acres"; | |
printf("Before Reverse: %s\n", strArray); | |
reverse(strArray); | |
printf("After Reverse: %s\n", strArray); | |
} |
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 uniqueString(str): | |
"Return True if the string has all unique characters." | |
allChar = [] | |
for i in range(256): | |
allChar.append(True) | |
for char in str: | |
if(allChar[ord(char)]): | |
allChar[ord(char)] = False | |
else: | |
return False |
NewerOlder