From 7c60dee83b436e8e8a667bf9f191beced8de4fc3 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Mon, 10 Mar 2025 00:36:13 -0600 Subject: chore: move cpp and rust code to directory --- other/tallest_billboard.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 other/tallest_billboard.cpp (limited to 'other/tallest_billboard.cpp') diff --git a/other/tallest_billboard.cpp b/other/tallest_billboard.cpp new file mode 100644 index 0000000..1201823 --- /dev/null +++ b/other/tallest_billboard.cpp @@ -0,0 +1,26 @@ +#include "leetcode.h" + +class Solution { +public: + int tallestBillboard(vector &rods) { + unordered_map dp; + dp[0] = 0; + for (int i : rods) { + unordered_map tmp; + for (auto &it : dp) { + int diff = it.first; + tmp[diff + i] = max(tmp[diff + i], dp[diff] + i); + tmp[diff - i] = max(tmp[diff - i], dp[diff]); + } + dp.clear(); + dp.insert(tmp.begin(), tmp.end()); + } + return dp[0]; + } +}; + +int main() { + Solution obj; + vector rods = {1, 2, 3, 6}; + cout << obj.tallestBillboard(rods); +} -- cgit v1.2.3