From ea2bd027188543baf802a34bc7966eceebdc8f18 Mon Sep 17 00:00:00 2001 From: tree Date: Sat, 16 Mar 2024 13:50:21 +0900 Subject: [PATCH 1/4] ValidPalindrome --- ValidPalindrome.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 ValidPalindrome.js diff --git a/ValidPalindrome.js b/ValidPalindrome.js new file mode 100644 index 0000000..48c2494 --- /dev/null +++ b/ValidPalindrome.js @@ -0,0 +1,12 @@ +/** + * @param {string} s + * @return {boolean} + */ +const isPalindrome = function (s) { + const filteredStr = s.toLowerCase().replace(/[^a-z0-9]/g, ""); + + return filteredStr === filteredStr.split("").reverse().join(""); +}; + +const s = "A man, a plan, a canal: Panama"; +const x = isPalindrome(s); From dd74f1a6a46f9d96fbbc012da9a22f95a84a2656 Mon Sep 17 00:00:00 2001 From: tree Date: Sat, 16 Mar 2024 13:50:39 +0900 Subject: [PATCH 2/4] change file route --- ValidPalindrome.js => twoPointer/ValidPalindrome.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ValidPalindrome.js => twoPointer/ValidPalindrome.js (100%) diff --git a/ValidPalindrome.js b/twoPointer/ValidPalindrome.js similarity index 100% rename from ValidPalindrome.js rename to twoPointer/ValidPalindrome.js From 4d57b20b2df9810c66ed752798ceed82a90b96ed Mon Sep 17 00:00:00 2001 From: tree Date: Sat, 16 Mar 2024 14:26:31 +0900 Subject: [PATCH 3/4] InputArrayIsSorted v1 --- stack/DailyTemperatures.js | 2 ++ twoPointer/InputArrayIsSorted.js | 34 ++++++++++++++++++++++++++++++++ twoPointer/ValidPalindrome.js | 8 +++++++- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 twoPointer/InputArrayIsSorted.js diff --git a/stack/DailyTemperatures.js b/stack/DailyTemperatures.js index 4c2e83c..320410f 100644 --- a/stack/DailyTemperatures.js +++ b/stack/DailyTemperatures.js @@ -27,3 +27,5 @@ const dailyTemperatures = function (temperatures) { const x = dailyTemperatures(temperatures); console.log(x); + +// https://leetcode.com/problems/daily-temperatures/description/ diff --git a/twoPointer/InputArrayIsSorted.js b/twoPointer/InputArrayIsSorted.js new file mode 100644 index 0000000..c2e97a4 --- /dev/null +++ b/twoPointer/InputArrayIsSorted.js @@ -0,0 +1,34 @@ +/** + * @param {number[]} numbers + * @param {number} target + * @return {number[]} + */ + +/* +Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 <= index1 < index2 <= numbers.length. +Return the indices of the two numbers, index1 and index2, added by one as an integer array [index1, index2] of length 2. +The tests are generated such that there is exactly one solution. You may not use the same element twice. +Your solution must use only constant extra space. + */ +const twoSum = function (numbers, target) { + const obj = {}; + + for (let i = 0; i < numbers.length; i++) { + const x = target - numbers[i]; + if (obj.hasOwnProperty(x)) { + return [obj[x], i]; + } + obj[numbers[i]] = i; + } + + return []; +}; + +// 함수를 + +const numbers = [2, 7, 11, 15]; +const target = 9; + +const b = twoSum(numbers, target); + +// https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/description/ diff --git a/twoPointer/ValidPalindrome.js b/twoPointer/ValidPalindrome.js index 48c2494..8cb19da 100644 --- a/twoPointer/ValidPalindrome.js +++ b/twoPointer/ValidPalindrome.js @@ -2,11 +2,17 @@ * @param {string} s * @return {boolean} */ + +// A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, +// it reads the same forward and backward. Alphanumeric characters include letters and numbers. +// Given a string s, return true if it is a palindrome, or false otherwise. + const isPalindrome = function (s) { const filteredStr = s.toLowerCase().replace(/[^a-z0-9]/g, ""); - return filteredStr === filteredStr.split("").reverse().join(""); }; const s = "A man, a plan, a canal: Panama"; const x = isPalindrome(s); + +// https://leetcode.com/problems/valid-palindrome/description/ From 645425a15b726a9cbf4f74ab792fa4aa3c54077a Mon Sep 17 00:00:00 2001 From: tree Date: Sat, 1 Jun 2024 16:04:05 +0900 Subject: [PATCH 4/4] =?UTF-8?q?0601:=20=EC=B6=94=EC=96=B5=EC=A0=90?= =?UTF-8?q?=EC=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...24\354\226\265\354\240\220\354\210\230.js" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\266\224\354\226\265\354\240\220\354\210\230.js" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\266\224\354\226\265\354\240\220\354\210\230.js" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\266\224\354\226\265\354\240\220\354\210\230.js" new file mode 100644 index 0000000..add9e52 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\266\224\354\226\265\354\240\220\354\210\230.js" @@ -0,0 +1,28 @@ +const name = ["may", "kein", "kain", "radi"]; +const yearning = [5, 10, 1, 3]; +const photo = [ + ["may", "kein", "kain", "radi"], + ["may", "kein", "brin", "deny"], + ["kon", "kain", "may", "coni"], +]; + +function solution(name, yearning, photo) { + const answer = []; + const score = {}; + + name.forEach((x, i) => (score[x] = yearning[i])); + photo.forEach((list) => { + let num = 0; + list.forEach((v) => { + if (score.hasOwnProperty(v)) { + num += score[v]; + } + }); + answer.push(num); + num = 0; + }); + + return answer; +} + +console.log(solution(name, yearning, photo));