[Java] Leetcode 6. ZigZag Conversion [Array #7]

preview_player
Показать описание
In this video, I'm going to show you how to solve Leetcode 6. ZigZag Conversion which is related to Array.

Here’s a quick rundown of what you’re about to learn:
⭐️ Course Contents ⭐️
⌨️ (0:00) Question
⌨️ (1:25) Solution Explain
⌨️ (3:54) Code

In the end, you’ll have a really good understanding on how to solve Leetcode 6. ZigZag Conversion and questions that are similar to this Array.

Now, if you want to get good at Array, please checkout my Array playlist.

Рекомендации по теме
Комментарии
Автор

Very clear! Love the way you add comment/note of the code. thank you so much!

yalansun
Автор

Much prefer your solution than the one in top search results (Neetcode - he went with math approach). I couldn't come up with the math formula.

Stringbuilder solution is easier to understand and code.

Great explanation, btw! 👍

CostaKazistov
Автор

Great explanation!! I went ahead and referenced a lot of your code in my solution since I was very stuck. I will say it helps a lot to make your variable names something relevant, because I wasn't really sure what the 'n' or 'index' referred to in your solution. Thanks man :)

vicentej
Автор

This is an amazing approach. Thank you!

raj_kundalia
Автор

thanks you, your solution is very easy to understand

saurabhdayal
Автор

what is the reason for index++ in append

jackyshi
Автор

Hey, just curious, why in the 2nd for loop in the while statement do we set "j" to be "numRows - 2"? I am trying to wrap my head around that part, but the rest makes a lot of sense, thanks :)

flatsodaclub
Автор

I see in the video that you are talking about cycles and put as a goal identifying that cycle . But what if the string is not that string ? What if the string has no repeated characters, so that there is no cycles anymore?

sakkamouid
Автор

its not optimal soln as space complexity is not good

RohanKumar-zmcx
Автор

time complexity= 0(n and whats the space complexity

nikhilpoonia
Автор

Thank you, this helped me come up with the following solution in Javascript

/**
* @param {string} s
* @param {number} numRows
* @return {string}
*/
var convert = function(s, numRows) {
if(numRows <= 1) return s;
let hashMap = {};
let arrayOfIndexes = [];
for(let i = 0; i < numRows; i++) {
hashMap[i] = '';
arrayOfIndexes.push(i);
}
let superCounter = numRows - 1;
let down = false;
for(let j = 0; j < s.length; j++) {
let index;
if(j < numRows) {
index = j;
hashMap[index] += s[j];
continue;
}

if(down) {
superCounter++;
hashMap[superCounter] += s[j];
down = superCounter < numRows - 1;
continue;
} else {
superCounter--;
hashMap[superCounter] += s[j];
down = superCounter === 0;
continue;
}
}
let output = '';
for(h in hashMap) {
output += hashMap[h];
}
console.log(hashMap, output, 'hashMap');
return output;
};

rachelcarengreen
Автор

really fab . Hey behind you is there is a baby .

hmmgmm
Автор

funny to read these comments, not very well explained for my simple brain. Then again, is there any practical application for this?

VincentTubed