8000 Update README.md · abroroo/leetcode@6e8928f · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e8928f

Browse files
authored
Update README.md
1 parent f7325c5 commit 6e8928f

File tree

1 file changed

+181
-1
lines changed

1 file changed

+181
-1
lines changed

README.md

Lines changed: 181 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
# My Solution to LeetCode problems
1+
# My Solution to LeetCode and Codewars problems
22

33
List is periodically updated
44

5+
## LeetCode
6+
7+
58
### #118. Pascal's Triangle
69

710
```
@@ -173,3 +176,180 @@ return nums1
173176
174177
};
175178
```
179+
180+
## CodeWars
181+
182+
### #The Hashtag Generator
183+
184+
```
185+
function generateHashtag (str) {
186+
let res = [];
187+
if (str.trim() === ''){
188+
res = false
189+
} else {
190+
res = "#" + str.split(' ').filter(w => (w !== '')).map(x => x[0].toUpperCase() + x.replace(x[0], '')).join('')
191+
}
192+
193+
return res.length > 140 ? false : res
194+
}
195+
196+
```
197+
198+
### #Extract the domain name from a URL
199+
200+
```
201+
function domainName(url){
202+
return url.replace('http://', '').replace('https://','').replace('www.','').replace('.com','').split(/[/.?#]/)[0];
203+
}
204+
```
205+
206+
### #Number of trailing zeros of N!
207+
208+
```
209+
function zeros (n) {
210+
211+
let numZ = 0;
212+
213+
for (let i = 5; Math.floor(n / i) >= 1; i *= 5){
214+
numZ += Math.floor(n / i);
215+
}
216+
217+
return numZ;
218+
}
219+
```
220+
221+
### #Bit Counting
222+
223+
```
224+
def count_bits(n):
225+
bnum = "{0:b}".format(n)
226+
return sum(int(digit) for digit in bnum)
227+
228+
```
229+
230+
### #Valid Parentheses
231+
232+
```
233+
function validParentheses(parens){
234+
let arr = [];
235+
let model = {
236+
"(": ")"
237+
}
238+
239+
for (let i = 0; i < parens.length; i++){
240+
if(parens[i] === "("){
241+
arr.push(parens[i]);
242+
} else {
243+
let closing = arr.pop();
244+
if (parens[i] !== model[closing]){
245+
return false;
246+
}
247+
}
248+
}
249+
if (arr.length !== 0){return false;}
250+
251+
return true;
252+
}
253+
```
254+
255+
### #Moving Zeros To The End
256+
257+
```
258+
var moveZeros = function (arr) {
259+
let zero = []
260+
let others = []
261+
let together = []
262+
263+
for (let i =0; i <= arr.length-1; i++){
264+
if (arr[i] === 0){
265+
zero.push(arr[i])
266+
}
267+
else{
268+
others.push(arr[i])
269+
}
270+
}
271+
together = others.concat(zero)
272+
return together
273+
}
274+
```
275+
276+
### #Find the next perfect square!
277+
278+
```
279+
function findNextSquare(sq) {
280+
if (sq % Math.sqrt(sq) === 0){
281+
return Math.pow((Math.sqrt(sq) + 1), 2);
282+
} else {
283+
return -1;
284+
}
285+
286+
}
287+
```
288+
289+
### #Binary Addition
290+
291+
```
292+
function addBinary(a,b) {
293+
let sum = a + b;
294+
return (sum).toString(2);
295+
}
296+
```
297+
298+
### #Does my number look big in this?
299+
300+
```
301+
function narcissistic(value) {
302+
let arrValue = value.toString().split("");
303+
let newArr = [];
304+
305+
for(var i=0; i<arrValue.length;i++) arrValue[i] = parseInt(arrValue[i], 10);
306+
307+
for (let j = 0; j < arrValue.length; j++){
308+
newArr.push(Math.pow(arrValue[j], arrValue.length));
309+
}
310+
if (newArr.reduce((a, b) => a + b, 0) === value){
311+
return true
312+
} else {
313+
return false
314+
}
315+
316+
}
317+
```
318+
319+
### #Sum of two lowest positive integers
320+
321+
```
322+
function sumTwoSmallestNumbers(numbers) {
323+
324+
var arr = numbers.sort((a, b) => a - b).slice(0, 2);
325+
326+
return arr[0] + arr[1];
327+
328+
}
329+
330+
```
331+
332+
### #Disemvowel Trolls
333+
334+
```
335+
function disemvowel(str) {
336+
return str.replace(/[aeiou]/gim, "");
337+
}
338+
```
339+
340+
### #Stop gninnipS My sdroW!
341+
342+
```
343+
function spinWords(str) {
344+
let arr = str.split(' ');
345+
346+
for (let i = 0; i < arr.length; i++) {
347+
if (arr[i].length > 4) {
348+
arr[i] = arr[i].split('').reverse().join('');
349+
}
350+
}
351+
return arr.join(' ');
352+
}
353+
```
354+
355+
### #

0 commit comments

Comments
 (0)
0