From 9952c85bd1a041c8c3080d200dab8564e202b473 Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Wed, 17 Nov 2021 14:55:11 +0000 Subject: [PATCH] Add leetcode 318 --- LeetCode-CN/318.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 LeetCode-CN/318.cpp diff --git a/LeetCode-CN/318.cpp b/LeetCode-CN/318.cpp new file mode 100644 index 0000000..4bd1184 --- /dev/null +++ b/LeetCode-CN/318.cpp @@ -0,0 +1,26 @@ +class Solution { +public: + int maxProduct(vector& words) { + const int N = words.size(); + vector mark; + for (auto& s : words) { + int32_t m = 0; + for (auto& c : s) { + m |= 1 << (c - 'a'); + } + mark.push_back(m); + } + + size_t ret = 0; + for (int i = 0; i < N; i++) + { + for (int j = i + 1; j < N; j++) + { + if (!(mark[i] & mark[j])) { + ret = max(ret, words[i].size() * words[j].size()); + } + } + } + return ret; + } +}; \ No newline at end of file