본문 바로가기

반응형

열정가득한 개발자의 이야기/Javascript Algorithm

(16)
1768. Merge Strings Alternately (JS) hi. I've solved a problem related to strings.It was simple, so I solved it right away. I'm so happy! Anyway, I'm going to explain this problem.There are two strings, and you need to combine them character by character, not string by string.However, some strings have different lengths.So, regardless of whether their lengths match or not, you should merge them one character at a time. Here’s my so..
1071. Greatest Common Divisor of Strings (JS) hi. I have another question about a LeetCode problem.First, please check what the problem is.It's quite a simple one, but it was hard to implement in code.I'm not an AI, so it's really difficult to explain in a programming language.I tried using the substr and includes methods,but they didn't work properly.They couldn't cover all the cases.So... I googled the answer and re-realized the power of ..
151. Reverse Words in a String (Javascript) Hi!I solved a LeetCode problem about strings.It's categorized as a medium problem, but I found it not too difficult.I tried solving it, and I succeeded!Anyway, let me explain the problem description.Remove leading and trailing spaces.If there are multiple spaces between words, reduce them to a single space.The goal is not to reverse the string character by character, but to reverse it word by wo..
643. Maximum Average Subarray I with JS Hi! Long time no see.I've been so busy looking for a job, working, studying English, and learning new tech stacks... T_TBut algorithms are one of the most important things when preparing for a job, so I'm back! Hahaha.Anyway, today I solved a problem about arrays. First, this is my own code. It was too long and unfortunately, it caused a time limit exceeded (TLE) error... 😭Why did I write my co..
leetcode 575. Distribute Candies (javascript) Hi! Happy New Year to you too! I'm in Korea for a while to celebrate the Korean New Year with my family.Even though I'm on holiday, I'm still studying algorithms to improve my logical thinking. Anyway, this is what I'd solved. Summary of My Solution:This problem involves using arrays and the Set data structure to determine the maximum number of unique types.Here's my approach:Initially, I solved..
500. Keyboard Row (javascript) Hi, today I worked on a problem that seems to be related to Hash Maps.To summarize:there are three layers, so I tried using a Map like ["a", "1"], ["b", "2"].However, it didn’t work properly.To solve the problem in my own way, I used a String and compared values directly.Yeah... the code ended up being really long, and the efficiency isn’t great.But I think solving the problem is more important ..
leet code 409. Longest Palindrome Hi there. I bring the new problem again 👋this time, I need to find out longest palindrome's length..what the..I really hate... palindrome... why the name is so long...palin.. what..?anyway..this is the description.  this is my own code.  var longestPalindrome = function(s) {   let x = s.split('').sort().join('')       --> why I converted the String to Array? because I need to use IndexOf method..
leet code 387. First Unique Character in a String (javascript) here is my answer var firstUniqChar = function(s) {//for getting the count of element, I think Map is necessary.//so I declared the Map and used for loop for checking the count. let a = new Map()for(let i = 0; i  s.length; i++){if(a.has(s[i])){a.set(s[i], a.get(s[i])+1)}else{a.set(s[i], 1)}} //after saving the count on Map,//i need to find out the first factor which is on the first.// so I use i..

반응형