Skip to content

Instantly share code, notes, and snippets.

😀

Danilo Oliveira DaniloOliveira28

😀
Block or report user

Report or block DaniloOliveira28

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Ex8
def get_max_brute_force(lst):
if len(lst) == 1:
return lst[0]
maximum = lst[0]
for i in range(1, len(lst)):
if lst[i] > maximum:
maximum = lst[i]
View Ex7 - List 2
def mergesort(lst):
'''Recursively divides list in halves to be sorted'''
if len(lst) == 1:
return lst, 0
middle = len(lst) / 2
left = mergesort(lst[:middle])[0] # Ignore intermediate splits
right = mergesort(lst[middle:])[0] # Ignore intermediate splits
sortedlist, splits = merge(left, right)
return sortedlist, splits
View Ex10
def exp(a, n):
if n <= 0:
return 1
if n % 2 == 0:
return exp(a, n / 2) * exp(a, n / 2)
else:
return exp(a, (n - 1) / 2) * exp(a, (n - 1) / 2) * a
if __name__ == '__main__':
View Ex6
def find_peak(elements):
if len(elements) < 0:
return None
if len(elements) == 1:
return elements[0]
if len(elements) == 2:
if elements[0] > elements[1]:
return elements[0]
View Ex5 c-d
#!/usr/local/bin/python2.7
# encoding: utf-8
import numpy as np
def equal_letters_strings(X, Y):
N = len(X)
M = len(Y)
View Ex4c-d - Algoritmos
def maxProfit(prices):
if len(prices) < 2:
return 0
s0 = dict()
s1 = dict()
s2 = dict()
s0[0] = 0
s1[0] = -prices[0]
s2[0] = 0
View Ex2-C Algoritmos
def n_lower_chars(string):
return sum(1 for c in string if c.islower())
def n_lower_chars_position(string):
return list((x, string[x] + "->" + string[x].upper())
for x in range(0, len(string)) if string[x].islower())
def format_word(word):
View Ex2-B Algoritmos
def n_lower_chars(string):
return sum(1 for c in string if c.islower())
def format_word(word):
if word == word.upper() or word == word.lower():
return 0
M = dict()
M[0] = 0
View Ex1-D Lista2 Algoritmos
def is_palindrome(palavra):
return palavra[::-1] == palavra
def palindrome(texto):
if len(texto) <= 1:
return 0, ["None"]
res_pal = is_palindrome(texto)
if res_pal is True:
return 0, ["None"]
View Ex1-C Lista2 Algoritmos
def is_palindrome(palavra):
return palavra[::-1] == palavra
def palindrome(texto):
if len(texto) <= 1:
return 0
res_pal = is_palindrome(texto)
if res_pal is True:
return 0
You can’t perform that action at this time.