From 1ab873bfa53ae64c1d601fe61b36a6e9baf0c7cd Mon Sep 17 00:00:00 2001 From: Yubo Liu Date: Thu, 2 May 2019 09:33:05 -0700 Subject: [PATCH] readme.md --- 0458-Poor-Pigs/cpp-0458/CMakeLists.txt | 6 +++++ 0458-Poor-Pigs/cpp-0458/main.cpp | 32 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 0458-Poor-Pigs/cpp-0458/CMakeLists.txt create mode 100644 0458-Poor-Pigs/cpp-0458/main.cpp diff --git a/0458-Poor-Pigs/cpp-0458/CMakeLists.txt b/0458-Poor-Pigs/cpp-0458/CMakeLists.txt new file mode 100644 index 00000000..f543e352 --- /dev/null +++ b/0458-Poor-Pigs/cpp-0458/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.14) +project(cpp_0458) + +set(CMAKE_CXX_STANDARD 14) + +add_executable(cpp_0458 main.cpp) \ No newline at end of file diff --git a/0458-Poor-Pigs/cpp-0458/main.cpp b/0458-Poor-Pigs/cpp-0458/main.cpp new file mode 100644 index 00000000..1f5fd319 --- /dev/null +++ b/0458-Poor-Pigs/cpp-0458/main.cpp @@ -0,0 +1,32 @@ +/// Source : https://leetcode.com/problems/poor-pigs/ +/// Author : liuyubobobo +/// Time : 2019-05-02 + +#include +#include + +using namespace std; + + +/// Mathematics +/// A better explanation than official solution if here: +/// https://leetcode.com/problems/poor-pigs/discuss/94266/Another-explanation-and-solution +/// +/// Time Complexity: O(log(buckets)) +/// Space Complexity: O(1) +class Solution { +public: + int poorPigs(int buckets, int minutesToDie, int minutesToTest) { + + int res = 0; + while((int)pow(minutesToTest / minutesToDie + 1, res) < buckets) + res ++; + return res; + } +}; + + +int main() { + + return 0; +} \ No newline at end of file