diff options
author | Yuchen Pei <me@ypei.me> | 2020-08-02 21:34:32 +0200 |
---|---|---|
committer | Yuchen Pei <me@ypei.me> | 2020-08-02 21:34:32 +0200 |
commit | 78e79c7688feae5e0da75a87f7f6293c8502125a (patch) | |
tree | 1503eaf6e2c370ad293282296629b0eec1e9f69e /microposts/ia-lawsuit.md~ | |
parent | b04ffe8778fe71028dcab51eecd1450a98244618 (diff) |
Added two mposts on ia and fsf
Diffstat (limited to 'microposts/ia-lawsuit.md~')
-rw-r--r-- | microposts/ia-lawsuit.md~ | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/microposts/ia-lawsuit.md~ b/microposts/ia-lawsuit.md~ new file mode 100644 index 0000000..e3e0f9c --- /dev/null +++ b/microposts/ia-lawsuit.md~ @@ -0,0 +1,17 @@ +--- +date: 2018-06-04 +--- + +The [Boyer-Moore algorithm for finding the majority of a sequence of elements](https://en.wikipedia.org/wiki/Boyer–Moore_majority_vote_algorithm) falls in the category of "very clever algorithms". + + int majorityElement(vector<int>& xs) { + int count = 0; + int maj = xs[0]; + for (auto x : xs) { + if (x == maj) count++; + else if (count == 0) maj = x; + else count--; + } + return maj; + } + |