摘要: 这道题经过独立思考,通过使用二进制编码的方式来进行处理。分几个步骤一层一层的处理,最终解决了,这道题感觉应该属于medimu级别。 另一种解法,使用回溯法: 再提供一种回溯法的思路,使用python实现: 阅读全文
posted @ 2018-09-29 21:52 Sempron2800+ 阅读(115) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: int Binary_Search(vector x, int N, int keyword) { int low = 0, high = N - 1, mid; while (low fairCandySwap(vector& A, vector& B) { int sumA =... 阅读全文
posted @ 2018-09-29 17:35 Sempron2800+ 阅读(127) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: bool isMonotonic(vector& A) { if (A.size() A[i + 1])//应该是增序列,但遇到左>右,则表示false { return false; } ... 阅读全文
posted @ 2018-09-29 16:58 Sempron2800+ 阅读(81) 评论(0) 推荐(0) 编辑
摘要: 这道题因为有0的情况,因此不能使用投影的方法,需要遍历每一个元素,单独处理。 阅读全文
posted @ 2018-09-29 14:27 Sempron2800+ 阅读(145) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: void SplitString(const string& s, vector& v, const string& c) { string::size_type pos1, pos2; pos2 = s.find(c); pos1 = 0; while (strin... 阅读全文
posted @ 2018-09-29 12:41 Sempron2800+ 阅读(89) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: bool IsPrime(int n) { if (n == 1) { return false; } if (n == 2 || n == 3) { return true; } ... 阅读全文
posted @ 2018-09-29 11:45 Sempron2800+ 阅读(101) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: bool hasAlternatingBits(int n) { int last = -1; while (n) { int x = n & 1; if (last == -1) { ... 阅读全文
posted @ 2018-09-29 11:06 Sempron2800+ 阅读(78) 评论(0) 推荐(0) 编辑
摘要: 这道题用C++来写,在本地执行正常,但是使用OJ判断输出结果是空,暂时不清楚原因。代码如下: 保留原有逻辑,修改为C#代码,则通过所有测试,代码如下: 不知是leetcode的判断机制问题,还是我的C++写法的问题。之后还是尽量使用C#吧。 阅读全文
posted @ 2018-09-29 00:29 Sempron2800+ 阅读(138) 评论(0) 推荐(0) 编辑