본문 바로가기

Algorithm/Implementation

(750)
(C++) - LeetCode (easy) 119. Pascal's Triangle II https://leetcode.com/problems/pascals-triangle-ii/ Pascal's Triangle II - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com pascal 삼각형을 구현하는 문제였습니다. 📕 풀이방법 📔 풀이과정 만들어야 할 행의 개수는 numRows만큼, 매 행마다 만들어야할 열의 개수는 각 행번째만큼입니다.이차원 for loop를 수행해 각 행에 필요한 vector tmp에 원소를 구해 저장해줍니다. 1. pascal 삼각..
(C++) - LeetCode (easy) 118. Pascal's Triangle https://leetcode.com/problems/pascals-triangle/ Pascal's Triangle - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 📕 풀이방법 📔 풀이과정 만들어야 할 행의 개수는 numRows만큼, 매 행마다 만들어야할 열의 개수는 각 행번째만큼입니다.이차원 for loop를 수행해 각 행에 필요한 vector tmp에 원소를 구해 저장해줍니다. 1. pascal 삼각형은 i행과 j 열이 같은 값이거나 j열인 경우 1의 값..
(C++) - LeetCode (easy) 69. Sqrt(x) https://leetcode.com/problems/sqrtx/ Sqrt(x) - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com sqrt함수를 사용해보는 간단한 문제였습니다. 📕 풀이방법 📔 정답출력 sqrt(x)를 반환합니다. 함수의 반환형이 int이므로 실수부를 생략할 수 있습니다. 📕 Code 📔 C++ #include class Solution { public: int mySqrt(int x) { return sqrt(x); } }; *더 나은 내용을 ..
(Python) - LeetCode (easy) 67. Add Binary https://leetcode.com/problems/add-binary/ Add Binary - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 이진수 변환 문제였습니다. 📕 풀이방법 📔 풀이과정 1. binary string인 a, b를 10진수로 변환 후 더해줍니다. 2. 더해준 값을 다시 binary string으로 바꾸고 2번째 문자까지 slice한 문자를 반환합니다. 📕 Code 📔 python class Solution: def addBinary(se..
(Python) - LeetCode (easy) 66. Plus One https://leetcode.com/problems/plus-one/ Plus One - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com bigint를 지원하는 언어에 한에서 쉬웠던 구현 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 지역변수 sum을 선언 후 0으로 초기화해줍니다. 📔 풀이과정 1. digits의 원소에 대해 for loop를 수행하며 각 자릿수마다 sum에 list의 원소를 더하며 10을 곱해주면 기존의 큰 int값을 구할 수 있습니다. 2...
(C++) - LeetCode (easy) 13. Roman to Integer https://leetcode.com/problems/roman-to-integer/ Roman to Integer - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 간단 분기 구현 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 각 symbol에 맞는 수를 반환하기 위한 map변수 symbolMap을 선언 후 초기화해줍니다. 📔 풀이과정 for loop를 수행하며 문자열 s를 확인해줍니다. 매 loop당 3 조건에 대해 고려해줍니다. 바로 다음 문자만 확인하면 ..
(C++) - 백준(BOJ) 3533 : Explicit Formula https://www.acmicpc.net/problem/3533 3533번: Explicit Formula Consider 10 Boolean variables x1, x2, x3, x4, x5, x6, x7, x8, x9, and x10. Consider all pairs and triplets of distinct variables among these ten. (There are 45 pairs and 120 triplets.) Count the number of pairs and triplets that contain at least one variab www.acmicpc.net 간단 구현 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 x1 ~ x10까지 선언해줍니다. 📔 정답출력 공식의 결과..
(C++, Rust) - 백준(BOJ) 13236 : Collatz Conjecture https://www.acmicpc.net/problem/13236 13236번: Collatz Conjecture The Collatz conjecture is a conjecture in mathematics named after Lothar Collatz, who first proposed it in 1937 and is still an open problem in mathematics. The sequence of numbers involved is referred to as the hailstone sequence or hailstone numbers (b www.acmicpc.net 간단 구현 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 초기 숫자 n을 선언해 줍니다. 📔 풀이과정 조건에 따..