๋ฌธ์ ์๋ผํ ์คํ
๋ค์ค์ ์ฒด๋ N๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ ๋ชจ๋ ์์๋ฅผ ์ฐพ๋ ์ ๋ช
ํ ์๊ณ ๋ฆฌ์ฆ์ด๋ค. ์ด ์๊ณ ๋ฆฌ์ฆ์ ๋ค์๊ณผ ๊ฐ๋ค. 2๋ถํฐ N๊น์ง ๋ชจ๋ ์ ์๋ฅผ ์ ๋๋ค. ์์ง ์ง์ฐ์ง ์์ ์ ์ค ๊ฐ์ฅ ์์ ์๋ฅผ ์ฐพ๋๋ค. ์ด๊ฒ์ P๋ผ๊ณ ํ๊ณ , ์ด ์๋ ์์์ด๋ค. P๋ฅผ ์ง์ฐ๊ณ , ์์ง ์ง์ฐ์ง ์์ P์ ๋ฐฐ์๋ฅผ ํฌ๊ธฐ ์์๋๋ก ์ง์ด๋ค. ์์ง ๋ชจ๋ ์๋ฅผ ์ง์ฐ์ง ์์๋ค๋ฉด, ๋ค์ 2๋ฒ ๋จ๊ณ๋ก ๊ฐ๋ค. N, K๊ฐ ์ฃผ์ด์ก์ ๋, K๋ฒ์งธ ์ง์ฐ๋ ์๋ฅผ ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. ์
๋ ฅ ์ฒซ์งธ ์ค์ N๊ณผ K๊ฐ ์ฃผ์ด์ง๋ค. (1 ≤ K < N, max(2, K) < N ≤ 1000) ์ถ๋ ฅ ์ฒซ์งธ ์ค์ K๋ฒ์งธ ์ง์์ง ์๋ฅผ ์ถ๋ ฅํ๋ค. ์์ ์
๋ ฅ 1 10 7 ์์ ์ถ๋ ฅ 1 9 ํํธ 2, 4, 6, 8, 10, 3, 9, 5, 7 ์์๋๋ก ์ง์์ง๋ค. 7๋ฒ์งธ ์ง..
๐ฅ๏ธ Computer
Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at a random position. Find the letter that was added in t. Example: Input: s = "abcd" t = "abcde" Output: e Explanation: 'e' is the letter that was added. ์ฝ๋ class Solution { public: char findTheDifference(string s, string t) { long int arr1[27] = {0,..
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If n is odd, you can replace n with either n + 1 or n - 1. What is the minimum number of replacements needed for n to become 1? Example 1: Input: 8 Output: 3 Explanation: 8 -> 4 -> 2 -> 1 Example 2: Input: 7 Output: 4 Explanation: 7 -> 8 -> 4 -> 2 -> 1 or 7 -> 6 -> 3 -> 2 -> 1 ์ฝ๋ class Solution { pu..
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad. Suppose you have n versions [1, 2, ..., n] and you want to find out the first bad one, which causes all the following ones to be..
7. Reverse Integer Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Example 2: Input: -123 Output: -321 Example 3: Input: 120 Output: 21 Note: Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 0 when the ..
๋ฌธ์ ์ฐ๋ฆฌ๋ ์ฌ๋์ ๋ฉ์น๋ฅผ ํค์ ๋ชธ๋ฌด๊ฒ, ์ด ๋ ๊ฐ์ ๊ฐ์ผ๋ก ํํํ์ฌ ๊ทธ ๋ฑ์๋ฅผ ๋งค๊ฒจ๋ณด๋ ค๊ณ ํ๋ค. ์ด๋ค ์ฌ๋์ ๋ชธ๋ฌด๊ฒ๊ฐ x kg์ด๊ณ ํค๊ฐ y cm๋ผ๋ฉด ์ด ์ฌ๋์ ๋ฉ์น๋ (x,y)๋ก ํ์๋๋ค. ๋ ์ฌ๋ A ์ B์ ๋ฉ์น๊ฐ ๊ฐ๊ฐ (x,y), (p,q)๋ผ๊ณ ํ ๋ x>p ๊ทธ๋ฆฌ๊ณ y>q ์ด๋ผ๋ฉด ์ฐ๋ฆฌ๋ A์ ๋ฉ์น๊ฐ B์ ๋ฉ์น๋ณด๋ค "๋ ํฌ๋ค"๊ณ ๋งํ๋ค. ์๋ฅผ ๋ค์ด ์ด๋ค A, B ๋ ์ฌ๋์ ๋ฉ์น๊ฐ ๊ฐ๊ฐ (56,177), (45,165) ๋ผ๊ณ ํ๋ค๋ฉด A์ ๋ฉ์น๊ฐ B๋ณด๋ค ํฐ ์
์ด ๋๋ค. ๊ทธ๋ฐ๋ฐ ์๋ก ๋ค๋ฅธ ๋ฉ์น๋ผ๋ฆฌ ํฌ๊ธฐ๋ฅผ ์ ํ ์ ์๋ ๊ฒฝ์ฐ๋ ์๋ค. ์๋ฅผ ๋ค์ด ๋ ์ฌ๋ C์ D์ ๋ฉ์น๊ฐ ๊ฐ๊ฐ (45, 181), (55,173)์ด๋ผ๋ฉด ๋ชธ๋ฌด๊ฒ๋ D๊ฐ C๋ณด๋ค ๋ ๋ฌด๊ฒ๊ณ , ํค๋ C๊ฐ ๋ ํฌ๋ฏ๋ก, "๋ฉ์น"๋ก๋ง ๋ณผ ๋ C์ D๋ ๋..