[LeetCode] 283. Move Zeroes
·
코딩테스트/Python
🔗 Problem Linkhttps://leetcode.com/problems/move-zeroes/description/❔Thinking숫자 배열 nums가 주어지면, 0을 오른쪽으로 옮기면서 다른 숫자의 순서는 유지해야 한다.새로운 배열을 생성하지 않아야 하기 때문에, 값을 swap하는 방식을 택한다.💻Solution1. 0이 아닌 숫자의 인덱스를 찾는 방식def moveZeroes(self, nums: List[int]) -> None: for i in range(len(nums)): if nums[i] == 0: flag = False non_zero_idx = i while non_zero_idx   2. 투 포인터..
[LangChain] 챗봇 구성하기
·
ML_DL/MUJAKJUNG (무작정 시리즈)
[LangChain] 시작하기LangChain 이란?LLM을 활용한 어플리케이션 개발을 위한 오픈소스 프레임워크DB, File System 지원LangChain 설치가상환경 설정conda create -n langchain python=3.11langchain 설치pip install -U langchainopenai 설치pip installswwho.tistory.com 프로젝트 파일 구조chatbot_project/├── .env # 환경변수 저장├── main.py # 챗봇 실행 스크립트├── chatbot/│ ├── config.py # 환경변수 로드 및 설정│ ├── llm_chain.py # L..
[Programmers] Level 2. 아날로그 시계
·
코딩테스트/Python
🔗 Problem Link 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr❔Thinking아날로그 시계에서, 초침이 주어진 시간 범위 내에서의 시침 또는 분침과 일치하는 횟수를 반환한다.두개의 바늘이 겹친다는 의미는, 하나의 바늘이 1초 후에 다른 바늘보다 앞선다는 뜻과 동일하다.00시와 12시는 모든 바늘이 겹치는 구간이기 때문에, 정확히 예외처리를 해야 한다.💻Solutiondef solution(h1, m1, s1, h2, m2, s2): cnt = 0 init_time = h1*60*60 + m1*60 + s1 end_time = h2*60*60 + m2*60 + s2 i..
[LeetCode] 443. String Compression
·
코딩테스트/Python
🔗 Problem Linkhttps://leetcode.com/problems/string-compression/❔Thinking주어진 문자 배열을 압축한다 (ex - ['a','a'] -> ['a','2'])주어진 문자 배열에 압축한 결과를 저장한다.💻Solutiondef compress(self, chars: List[str]) -> int: compressed = [] n = len(chars) cnt = 0 for i in range(1, len(chars)): if chars[i] == chars[i-1]: cnt += 1 else: cnt += 1 compressed.append(cha..
[LeetCode] 238. Product of Array Except Self
·
코딩테스트/Python
🔗 Problem Linkhttps://leetcode.com/problems/product-of-array-except-self/❔Thinking배열이 주어지면, 자신의 원소를 제외한 모든 원소의 곱을 배열에 담아 반환한다.나누기 연산 없이, O(n)의 시간복잡도를 가지는 알고리즘을 작성해야 한다.💻Solutiondef productExceptSelf(self, nums: List[int]) -> List[int]: left, right = 1, 1 n = len(nums) answer = [1] * n for i in range(n): answer[i] *= left left *= nums[i] for i in range(n-1, -1, -1):..
[LeetCode] 345. Reverse Vowels of a String
·
코딩테스트/Python
🔗 Problem Linkhttps://leetcode.com/problems/reverse-vowels-of-a-string/description/❔Thinking영단어가 주어지면, 모음(a,e,i,o,u)만을 역순으로 재배치하여 반환한다. (abe -> eba)알파벳은 소문자와 대문자를 구분한다.💻Solution1. 단어에 포함된 모음을 배열에 담고, 해당 배열에서 pop 하여 순서 재배치def reverseVowels(self, s: str) -> str: vowels_set = set(['a','e','i','o','u','A','E','I','O','U']) vowels_list = [] s = list(s) for char in s: if char in v..