본문 바로가기

Algorithm220

[코딩 + 알고리즘 완주반] 5일차. 조건문, 반복문,List Comprehension, QUIZ #조건문 # 조건문 print(type(True)) # print(type(False)) #예1 if True: print("Yes") #예2 if False: print("Yes") #예3 if False: print("No") else: print("Yes2") # 관계연산자 # >, >=, =b) print(ab and b>c) print('or: ',a>b or c>b) print('not: ',not a>b) print(not False) print(not True) #산술, 관계, 논리 연산자 # 산술 > 관계 > 논리 순서로 적용 print('ex1 : ', 5+10>0 and not 7+3==10) score1 = 90 score2 = 'A' if score1 >=90 and score2 .. 2021. 3. 19.
[LEET CODE] 1. Two Sum 배열 : 메모리 공간 기반 연속 방식의 가장 기본이 되는 자료형 크기를 지정하고 해당 크기만큼의 연속된 메모리 공간을 할당받는 작업을 수행 어느 위치에나 O(1)에 조회 가능 동적 배열 : 크기를 지정하지 않고 자동으로 리사이징하는 배열 ( 파이썬의 List) 미리 초기값을 작게 잡아 배열을 생성하고, 데이터가 추가되면서 꽉 채워지면 늘려주고 모두 복사하는 방식 파이썬의 Growth Factor(성장 인자)는 초반에는 2배(더블링)씩 늘려가지만 전체적으로는 약 1,123배 ( 다른언어에 비해 조금만 늘려가는 형태) # Problem Given an array of integers nums and an integer target, return indices of the two numbers such tha.. 2021. 3. 19.
[코딩 + 알고리즘 완주반] 4일차. 딕셔너리, 집합, 데이터타입 퀴즈 # 딕셔너리 #딕셔너리(Dictionary) : 순서 X ,중복 X, 수정 O, 삭제 O # Key, Value (Json)---> MongoDB # 선언 a={'name': 'Kim','Phone': '010-7777-7777','birth':870214} # 키는 중복 안됨, 값은 중복 가능 b = {0:'Hello Python',1:'Hello Coding'} c = {'arr':[1,2,3,4,5]} # 모든 자료형을 값으로 넣을 수 있음 print(type(a)) # 키로 값 가져오기 print(a['name']) print(a.get('name')) print(a.get('address')) #get을 쓰면 없는 키도 오류가 나지 않음 print(c['arr'][1:3]) a['address'.. 2021. 3. 18.
[코딩 + 알고리즘 완주반] 3일차. 데이터타입, 숫자형, 문자형 및 연산자, 리스트, 튜플 # 파이썬 데이터 타입 종류 Boolean Numbers string bytes lists tuples sets dictionaries # 데이터 타입 v_str1 = "Niceman" v_bool = True V_str2 = "?Goodboy" v_float = 10.3 v_int = 7 v_dict = { "name" : "Kim", "age" : 25 } v_list = [3,5,7] v_tuple = 3,5,7 v_set = {7,8,9} print(type(v_tuple)) print(type(v_set)) print(type(v_float)) # 숫자형 및 연산자 + : 더하기 - : 빼기 * : 곱하기 / : 나누기 // : 몫 % : 나머지 ** : 지수 단항연산자 += -= *= /= i.. 2021. 3. 17.
[LEET CODE] 5. Longest Palindromic Substring #Problem Given a string s, return the longest palindromic substring in s. Example 1: Input : s = "babad" Output : "bab" Note : "aba" is also a valid answer. Constraints: 1 str: # 팰린드롬 판별 및 투 포인터 확장 # expand 함수는 중심에서 양쪽으로 계속 뻗어나간다. def expand(left: int, right: int) -> str: while left >= 0 and right < len(s) and s[left] == s[right]: left -= 1 right += 1 return s[left + 1:right] # 해당 사항이 없을때 빠르게 리턴.. 2021. 3. 16.
[코딩+알고리즘 완주반] 2일차. Print 함수, 가상환경 설정 # Print 가장 기본적인 출력 함수 Separator, End 옵션 사용 Format 형식 출력 Escape Code 사용 #Print 구문 #기본 출력 print('Hello python') print("Hello python") print("""hello python""") print('''hello python''') print() # 줄바꿈 #Separator 옵션 사용 print('T','E','S','T') print('T','E','S','T',sep='') print('2019','02','19',sep='-') print('niceman','google.com',sep='@') #end 옵션 사용 print('Welcome To',end=' ') print('the black para.. 2021. 3. 16.
반응형