Skip to content

Commit

Permalink
readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyubobobo committed May 2, 2019
1 parent 5ab397a commit 1ab873b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 0458-Poor-Pigs/cpp-0458/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.14)
project(cpp_0458)

set(CMAKE_CXX_STANDARD 14)

add_executable(cpp_0458 main.cpp)
32 changes: 32 additions & 0 deletions 0458-Poor-Pigs/cpp-0458/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// Source : https://leetcode.com/problems/poor-pigs/
/// Author : liuyubobobo
/// Time : 2019-05-02

#include <iostream>
#include <cmath>

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;
}

0 comments on commit 1ab873b

Please sign in to comment.