본문 바로가기

Algorithm

(2139)
(C++) - LeetCode (easy) 344. Reverse String https://leetcode.com/problems/reverse-string/description/ Reverse String - LeetCode Reverse String - Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place [https://en.wikipedia.org/wiki/In-place_algorithm] with O(1) extra memory. Example 1: leetcode.com 문자열 관련 함수 reverse를 사용해보는 문제였습니다. 📕 풀이방법 📔 풀이과정 ..
(C++) - LeetCode (easy) 342. Power of Four https://leetcode.com/problems/power-of-four/description/ Power of Four - LeetCode Power of Four - Given an integer n, return true if it is a power of four. Otherwise, return false. An integer n is a power of four, if there exists an integer x such that n == 4x. Example 1: Input: n = 16 Output: true Example 2: Input: n = 5 Output: fal leetcode.com 구현 문제였습니다. 📕 풀이방법 📔 풀이과정 1. 자료형이 int를 넘어갈 수 있으므로 ..
(C++) - LeetCode (easy) 338. Counting Bits https://leetcode.com/problems/counting-bits/description/ Counting Bits - LeetCode Can you solve this real interview question? Counting Bits - Given an integer n, return an array ans of length n + 1 such that for each i (0
(C++) - LeetCode (easy) 326. Power of Three https://leetcode.com/problems/power-of-three/description/ Power of Three - LeetCode Power of Three - Given an integer n, return true if it is a power of three. Otherwise, return false. An integer n is a power of three, if there exists an integer x such that n == 3x. Example 1: Input: n = 27 Output: true Explanation: 27 = 33 Example 2: leetcode.com 구현 문제였습니다. 📕 풀이방법 📔 풀이과정 i가 n보다 작은 동안 3씩 곱해주며 n과..
(C++) - LeetCode (easy) 303. Range Sum Query - Immutable https://leetcode.com/problems/range-sum-query-immutable/description/ Range Sum Query - Immutable - LeetCode Range Sum Query - Immutable - Given an integer array nums, handle multiple queries of the following type: 1. Calculate the sum of the elements of nums between indices left and right inclusive where left sumRange(left,right); */ *더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
(C++) - LeetCode (easy) 292. Nim Game https://leetcode.com/problems/nim-game/description/ Nim Game - LeetCode Nim Game - You are playing the following Nim Game with your friend: * Initially, there is a heap of stones on the table. * You and your friend will alternate taking turns, and you go first. * On each turn, the person whose turn it is will remove 1 to 3 sto leetcode.com 공식을 알아내 푸는 문제였습니다. 📕 풀이방법 📔 풀이과정 2^31까지 제한을 두므로 O(n)으로도 ..
(C++) - LeetCode (easy) 290. Word Pattern https://leetcode.com/problems/word-pattern/description/ 1) return false; vector v = split(s, ' '); if(pattern.size() != v.size()) return false; map m; map m2; for(int i = 0; i < v.size(); i++) { if(m2.count(pattern[i])) continue; m[v[i]] = pattern[i]; m2[pattern[i]] = v[i]; } for(int i = 0; i < v.size(); i++) { if(m[v[i]] != pattern[i]) { return false; } } return true; } }; *더 나은 내용을 위한 지적, 조언은 ..
(C++) - LeetCode (easy) 1470. Shuffle the Array https://leetcode.com/problems/shuffle-the-array/description/ Shuffle the Array - LeetCode Shuffle the Array - Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn]. Return the array in the form [x1,y1,x2,y2,...,xn,yn]. Example 1: Input: nums = [2,5,1,3,4,7], n = 3 Output: [2,3,5,4,1,7] Explanation: Since x1=2 leetcode.com 간단 구현 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 정답 변수 vec..