๐ค PS(Problem Solving)/Leet, ๊ตฌ๋ฆ
[๋งค์ผํ๋ก๊ทธ๋๋ฐ] ์ฝ๋ฉํ ์คํธ 07/08/2019
๋ฌธ์ ์ ์ ๋ฐฐ์ด(int array)๊ฐ ์ฃผ์ด์ง๋ฉด ๊ฐ์ฅ ํฐ ์ด์ด์ง๋ ์์๋ค์ ํฉ์ ๊ตฌํ์์ค. ๋จ, ์๊ฐ๋ณต์ก๋๋ O(n).Given an integer array, find the largest consecutive sum of elements. ์์ }Input: [-1, 3, -1, 5]Output: 7 // 3 + (-1) + 5 Input: [-5, -3, -1]Output: -1 // -1 Input: [2, 4, -2, -3, 8]Output: 9 // 2 + 4 + (-2) + (-3) + 8 ๋ด๊ฐ ์๊ฐํด๋ณธ ํ์ด๊ณผ์ 1.๊ท์น์๊ฐ ๋ณต์ก๋๋ O(n)์ ๋๋ค.๋ํด์ง๋ ์์๋ ๋ฐ๋์ ์ธ๋ฑ์ค๊ฐ ์ด์ด์ ธ ์์ด์ผ ํฉ๋๋ค. (arr[i] + arr[i+3] ๊ฐ์ ๊ฒฝ์ฐ๋ X) 2.์์ ์๊ฐ๋ณต์ก๋๊ฐ O(n)์ด๋ 2์ค f..
[LeetCode] 1108๋ฒ - Defanging an IP Address(IP์ฃผ์ ๋ชป์ฐ๊ฒ ๋ง๋ค๊ธฐ)
๋ฌธ์ 1108. Defanging an IP AddressEasy1687FavoriteShareGiven a valid (IPv4) IP address, return a defanged version of that IP address.A defanged IP address replaces every period "." with "[.]". Example 1:Input: address = "1.1.1.1" Output: "1[.]1[.]1[.]1" Example 2:Input: address = "255.100.50.0" Output: "255[.]100[.]50[.]0" Constraints:The given address is a valid IPv4 address. ํ์ด๊ณผ์ 1.๊ท์นIPv4 ์ฃผ์์ธ ์๋ฐฐ..
[LeetCode] 4๋ฒ - Median of Two Sorted Arrays(๋ ์ ๋ ฌ๋ ๋ฐฐ์ด์ ์ค์๊ฐ)
๋ฌธ์ 4. Median of Two Sorted ArraysHard4544636FavoriteShareThere are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).You may assume nums1 and nums2 cannot be both empty.Example 1:nums1 = [1, 3] nums2 = [2] The median is 2.0 Example 2:nums1 = [1, 2] nums2 = [3, 4] The median is (2 + 3)/2 ..
[LeetCode] 832๋ฒ - Flipping an Image(์ ๋ค์ง๊ธฐ)
๋ฌธ์ 832. Flipping an ImageEasy529110FavoriteShareGiven a binary matrix A, we want to flip the image horizontally, then invert it, and return the resulting image.To flip an image horizontally means that each row of the image is reversed. For example, flipping [1, 1, 0] horizontally results in [0, 1, 1].To invert an image means that each 0 is replaced by 1, and each 1 is replaced by 0. For example,..
[LeetCode] 905๋ฒ - Sort Array By Parity(ํ์ง์ฑ ์ฌ๋ถ๋ก ๋ฐฐ์ด ์ ๋ ฌ)
๋ฌธ์ 905. Sort Array By ParityEasy48854FavoriteShareGiven an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A.You may return any answer array that satisfies this condition. Example 1:Input: [3,1,2,4] Output: [2,4,3,1] The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted. Note:1
[LeetCode] 217๋ฒ - Contains Duplicate(์ค๋ณต์ด ํฌํจ๋์ด ์๋๊ฐ?)
๋ฌธ์ [LeetCode ๋งํฌ]217. Contains DuplicateEasy416526FavoriteShareGiven an array of integers, find if the array contains any duplicates.Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.Example 1:Input: [1,2,3,1] Output: trueExample 2:Input: [1,2,3,4] Output: falseExample 3:Input: [1,1,1,3,3,4,3,2,4,2] Output: t..