From d383762daabcd4cc5914fdfd173d9748c459469d Mon Sep 17 00:00:00 2001 From: Saksham Gupta Date: Thu, 1 Oct 2020 23:15:30 +0530 Subject: [PATCH] added Armstrong_Number --- Leetcode/Armstrong_Number.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Leetcode/Armstrong_Number.cpp diff --git a/Leetcode/Armstrong_Number.cpp b/Leetcode/Armstrong_Number.cpp new file mode 100644 index 0000000..f49d63e --- /dev/null +++ b/Leetcode/Armstrong_Number.cpp @@ -0,0 +1,10 @@ +class Solution { +public: + bool isArmstrong(int N) { + const auto& n_str = to_string(N); + return accumulate(n_str.cbegin(), n_str.cend(), 0, + [&](const auto& x, const auto& y) { + return x + pow(y - '0', n_str.length()); + }) == N; + } +}