input = [3, 5, 6, 1, 2, 4]
def find_max_num(array):
max_num = array[0]
for num in array:
if max_num < num:
max_num = num
return max_num
result = find_max_num(input)
print(result)
input = "hello my name is sparta"
def find_max_occurred_alphabet(string):
alphabet_occurrence_array = [0] * 26
for char in string:
if not char.isalpha():
continue
index = ord(char) - ord('a')
alphabet_occurrence_array[index] += 1
max_index = 0
max_num = alphabet_occurrence_array[max_index]
for i, num in enumerate(alphabet_occurrence_array):
if max_num < num:
max_num = num
max_index = i
max_alphabet = chr(ord('a') + max_index)
return max_alphabet
result = find_max_occurred_alphabet(input)
print(result)
: 입력받은 리스트에 원소들 사이에 더하기 또는 곱하기를 통해 최대값을 반환
input = [0, 3, 5, 6, 1, 2, 4]
def find_max_plus_or_multiply(array):
current_num = array[0]
for i, num in enumerate(array):
if i == 0:
continue
if current_num + num > current_num * num:
current_num += num
else:
current_num *= num
return current_num
result = find_max_plus_or_multiply(input)
print(result)
: 입력받은 문자열에 반복되지않는 첫 문자를 반환
input = "abadabaccandipadfk"
def find_not_repeating_character(string):
alpha_list = []
alpha_repeating = []
for char in string:
alpha_first = True
if len(alpha_list) == 0:
alpha_list.append(char)
alpha_repeating.append(1)
continue
for i, alpha in enumerate(alpha_list):
if alpha == char:
alpha_repeating[i] += 1
alpha_first = False
break
if alpha_first:
alpha_list.append(char)
alpha_repeating.append(1)
print(alpha_list)
print(alpha_repeating)
for i, num in enumerate(alpha_repeating):
if num == 1:
return alpha_list[i]
return "_"
result = find_not_repeating_character(input)
print(result)
: 알고리즘을 실행하는 데 걸리는 시간을 표현하는 방법
In computer science, the time complexity is the computational complexity that describes the amount of computer time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm, supposing that each elementary operation takes a fixed amount of time to perform.
: 알고리즘의 성능을 수학적으로 표기하는 방법 중 하나
In computer science, big O notation is used to classify algorithms according to how their run time or space requirements grow as the input size grows.
https://en.wikipedia.org/wiki/Big_O_notation#Use_in_computer_science
알고리즘의 실행시간에 가장 많은 영향을 주는 반복문에 대해서 시간복잡도를 간단하게 표현할 수 있다.
, , 등