File tree Expand file tree Collapse file tree 4 files changed +73
-1
lines changed
Expand file tree Collapse file tree 4 files changed +73
-1
lines changed Original file line number Diff line number Diff line change 1+ ## 每日一题 - 三门问题 (Three Doors Problem / Monty Hall problem)
2+
3+ ### 信息卡片
4+
5+ 今天这道题不是算法题,而是一道概率论的经典问题,相当违反直觉,很有意思。题目描述如下:
6+
7+ - 时间: 2019-06-13
8+ - tag: ` Probability Theory `
9+
10+ ## 题目描述
11+
12+ ```
13+ 假设你在参加一个春节抽奖游戏,主持人在三个红包里面分别放了 1 块钱、1 块钱和 1000 块钱。你选中哪一个,你就可以领到对应的钱。当你选定一个红包之后,主持人会打开一个 1 块钱的红包,并给你一次机会更换所选红包。请问:应不应该换?
14+ ```
15+
16+ ## 答案
17+
18+ ** 要换** 。换了之后有 ` 2/3 ` 的概率拿到 1000 的红包。而不是直觉告诉我们的 ` 1/2 ` .
19+
20+ 这份[ 代码] ( ./answers/three-doors-problem.js ) 进行了多次实验,验证了这一结论。
21+
22+ ## 简要解释
23+
24+ 这里的核心在于,主持人不是随机打开一个红包,而是挑选了一定是 1 块钱的那个红包。
25+
26+ ## 详细解释
27+
28+ 以下链接给出了数学证明和非常详细的解释:有兴趣可以看看。
29+
30+ [ Monty Hall 问题] ( https://mp.weixin.qq.com/s?__biz=MzIzODExMDE5MA==&mid=445629202&idx=1&sn=451fe436511f2b00d2354e8dd074b7fa#rd )
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ tag: `Array`
2525
2626#### [ 347.Top K Frequent Elements] ( ./2019-06-08.md )
2727
28- tag: ` HashTable ` ` Heap `
28+ tag: ` Hash Table ` ` Heap `
2929
3030时间: 2019-06-08
3131
@@ -40,3 +40,10 @@ tag: `String` `Dynamic Programming` `Backtracking`
4040tag: ` Tree `
4141
4242时间: 2019-06-10
43+
44+
45+ ### [ 三门问题] ( ./2019-06-13.md )
46+
47+ tag: ` Probability Theory `
48+
49+ 时间: 2019-06-13
File renamed without changes.
Original file line number Diff line number Diff line change @@ -42,6 +42,9 @@ Explanation:
4242
4343## 代码
4444
45+ * 语言支持:JS,C++
46+
47+ Javascript Code:
4548``` js
4649/*
4750 * @lc app=leetcode id=199 lang=javascript
@@ -115,6 +118,38 @@ var rightSideView = function(root) {
115118 return ret;
116119};
117120```
121+ C++ Code:
122+ ``` C++
123+ /* *
124+ * Definition for a binary tree node.
125+ * struct TreeNode {
126+ * int val;
127+ * TreeNode *left;
128+ * TreeNode *right;
129+ * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
130+ * };
131+ */
132+ class Solution {
133+ public:
134+ vector<int > rightSideView(TreeNode* root) {
135+ auto ret = vector<int >();
136+ if (root == nullptr) return ret;
137+ auto q = queue<const TreeNode* >();
138+ q.push(root);
139+ while (!q.empty()) {
140+ auto sz = q.size();
141+ for (auto i = 0; i < sz; ++i) {
142+ auto n = q.front();
143+ q.pop();
144+ if (n->left != nullptr ) q.push(n->left);
145+ if (n->right != nullptr ) q.push(n->right);
146+ if (i == sz - 1) ret.push_back(n->val);
147+ }
148+ }
149+ return ret;
150+ }
151+ };
152+ ```
118153
119154## 扩展
120155
You can’t perform that action at this time.
0 commit comments