上一页 1 2 3 4 5 6 7 8 9 10 ··· 43 下一页
摘要: http://community.topcoder.com/stat?c=problem_statement&pm=13628&rd=16278标程是BFS,我用DFS,都可解。这里复杂的把pair写了hash函数,其实直接用个矩阵来存bool就可以了。#include #include #incl... 阅读全文
posted @ 2015-01-23 23:14 阿牧遥 阅读(373) 评论(0) 推荐(0) 编辑
摘要: http://community.topcoder.com/stat?c=problem_statement&pm=13625&rd=16278首先,如果记得曼哈顿距离最小值那个问题,会想起一维的情况可证,点出现在中位数那里是最小的。这里也可证明,四个点,出现在中位数位置是最小的。题解里的做法是,试... 阅读全文
posted @ 2015-01-22 23:24 阿牧遥 阅读(297) 评论(0) 推荐(0) 编辑
摘要: DP.类似最大和。就是要记录正的和负的两种情况。class Solution {public: int maxProduct(int A[], int n) { vector positive(n); vector minus(n); int resu... 阅读全文
posted @ 2014-12-31 23:15 阿牧遥 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 二分class Solution {public: /* test: [1] test: [2, 1] test: [3, 1, 2] test: [2, 3, 1] test: [3, 4, 1, 2] test: [3, 4, 5, 1, 2] *... 阅读全文
posted @ 2014-12-31 23:13 阿牧遥 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 二分,各种情况。class Solution {public: int findMin(vector &num) { int size = num.size(); int minVal = num[size-1]; findMinRe(num, 0, ... 阅读全文
posted @ 2014-12-31 23:12 阿牧遥 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 老题目。两个栈。class MinStack { stack stk; stack minstk;public: void push(int x) { stk.push(x); if (minstk.empty() || minstk.top() >= ... 阅读全文
posted @ 2014-12-31 23:11 阿牧遥 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 老题了。class Solution {public: ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { ListNode *tailA = headA; ListNode *tail... 阅读全文
posted @ 2014-12-31 23:10 阿牧遥 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 类似二分。class Solution {public: int findPeakElement(const vector &num) { int size = num.size(); int left = 0; int right = size - ... 阅读全文
posted @ 2014-12-31 23:09 阿牧遥 阅读(115) 评论(0) 推荐(0) 编辑
摘要: 用分桶的做法,思路参考自网友,很精妙。class Solution {public: int maximumGap(vector &num) { int size = num.size(); if (size minBucket(bucketSize, INT_M... 阅读全文
posted @ 2014-12-31 23:08 阿牧遥 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 本人的做法是转化成vector再处理,各种情况就比较简单了。class Solution {public: int compareVersion(string version1, string version2) { vector v1 = convert(version1); ... 阅读全文
posted @ 2014-12-31 23:07 阿牧遥 阅读(163) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 43 下一页