Skip to content

Instantly share code, notes, and snippets.

View iamgilvan's full-sized avatar

Gilvan Praxedes de Almeida iamgilvan

View GitHub Profile
import unittest
import time
from copy import deepcopy
# O (N)
def string_rotation_algo(s1: str, s2: str) -> bool:
s1 = sorted(s1);
s2 = sorted(s2);
return True if s1 == s2 else False
import unittest
import time
from copy import deepcopy
# O (MXN)
def zero_matrix_algo(matrix):
new_matrix = deepcopy(matrix)
for index_row, row in enumerate(matrix):
import unittest
import time
from copy import deepcopy
# O (NxN)
def rotate_matrix_algo(matrix):
"""rotates a matrix 90 degrees clockwise"""
new_matrix = deepcopy(matrix)
import unittest
import time
# O (N)
def string_compression_algo(main_word: str) -> str:
count = 0
compressed = ''
last_char = main_word[0] if len(main_word) > 0 else ''
if last_char == '':
import unittest
def one_way_pythonic(main_word: str, edited_work: str) -> bool:
diff = set(list(main_word)) - set(list(edited_work))
return False if len(diff) > 1 else True
# O (N)
def one_way_algo(main_word: str, edited_work: str) -> bool:
count = 0
import unittest
def url_ify_pythonic(sentence: str) -> str:
return sentence.strip().replace(' ', '%20')
# O (N)
def url_ify_algo(sentence: str) -> str:
txt = ''
is_first_char = True
import unittest
# O (N)
def check_permutation_using_sorted(word1: str, word2: str) -> bool:
word1, word2 = sorted(word1), sorted(word2)
if len(word1) > len(word2):
for i in range(0, len(word2)):
if word1[i] != word2[i]:
return False
return True
from collections import defaultdict
import time
from typing import List
import random
import unittest
def is_unique_char_using_dict(word: str) -> bool:
dict = {}
for char in word:
if char in dict:
@iamgilvan
iamgilvan / reverse_linked_list2.py
Created August 28, 2021 21:22
Reverse a linked list
#!/bin/python3
import math
import os
import random
import re
import sys
class SinglyLinkedListNode:
def __init__(self, node_data):
@iamgilvan
iamgilvan / reverse_linked_list.py
Last active August 28, 2021 04:44
Print in Reverse
#!/bin/python3
import math
import os
import random
import re
import sys
class SinglyLinkedListNode:
def __init__(self, node_data):