LeetCode 168 Problem 1 - Find Numbers with Even Number of Digits

preview_player
Показать описание
Site: Leetcode
Contest: 168
Problem Name: Find Numbers with Even Number of Digits
Problem Type: Greedy

Github Links:

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

Love that for Python you give the naive version and the Pythonic version. Please keep doing that going forward.

EricMesa
Автор

This video is so informative. Thanks so much. Would love to see tons of coding explanations in similar format :)

pritomdasradheshyam
Автор

Nice to see you back! Always interesting to compare languages.
As a side note, for the 2nd C++ solution at 6:22, I would suggest using the std::count_if algorithm (available since C++98), which does the same thing as the proposed solution with std::accumulate, but in a simpler and more expressive way. Since it maps directly to the problem statement, that would be my favorite C++ solution also.

VincentZalzal
Автор

Great to see you back! Waiting for your CPP journey video! I have been doing deep learning recently and I hope it can make it to NVidia in future.

dejavukun
Автор

Great video as always!

Summing booleans as integers would result in shorter code in python:
sum( len(str(x)) % 2 == 0 for x in nums)

andyl.
Автор

Sir very nice
Pls keep uploading such solution videos with brief discussion on core concept as well 😊
Only u r helping struggling competitive coders 🙏🏻

coderguy
Автор

Stupid question, would just taking the log base 10 of the number and if it is odd be sufficient ? Not sure why mapping to strings was needed, good work for presentation, damn good to see, already subscribed 😀

NonameBozo
Автор

C#:

input.Select(n => n.ToString().Length).Where(n => n%2==0).Count();

or shorter but slower

input.Select(n => n.ToString().Length).Count(n => n%2==0);

the_cheese_cultist
Автор

Why do you convert to string and then count the length? Wouldn't it be better to take the floor of mod10?

r.pizzamonkey
Автор

How can we come to know a problem should be solved in either O(n) or O(nlogn) or O(n^2) etc based on given memory and size constraints.
Please help me out.

manikantabandla
Автор

Instead of accumulate you could have used transform_reduce where transform is (to_string(e).size()%2 == 0)

RishabhRD
Автор

I just hope CodeChef skips over C++17 and introduces C++20 :)

DarshanSenTheComposer