上一页 1 ··· 14 15 16 17 18 19 20 21 22 ··· 43 下一页
摘要: 此题有点意思,先用快慢指针把链表从一半处断开,然后把后半段倒过来,然后再进行merge。注意断开时要把前面链表的最后置NULL,merge后要把最后节点next置NULL。#include #include #include using namespace std;class Solution {public: ListNode * reverseList(ListNode *head) { if (head == NULL) return NULL; ListNode *dummy = new ListNode(0); dummy->next ... 阅读全文
posted @ 2013-12-03 22:20 阿牧遥 阅读(186) 评论(0) 推荐(0)
摘要: http://oj.leetcode.com/problems/linked-list-cycle-ii/老题。当快慢指针相交时,通过方程或观察可知,从head到环开始点的距离和从相遇点开始是一样的,那么从相遇点和从开始点再一起走直到相遇就行了。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ... 阅读全文
posted @ 2013-12-03 21:32 阿牧遥 阅读(169) 评论(0) 推荐(0)
摘要: http://oj.leetcode.com/problems/linked-list-cycle/老题,快慢指针。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: bool hasCycle(ListNode *head) { ListNode *fast = head; ... 阅读全文
posted @ 2013-12-03 21:21 阿牧遥 阅读(132) 评论(0) 推荐(0)
摘要: http://community.topcoder.com/stat?c=problem_statement&pm=12730&rd=15701这道题有点意思。首先把字符串变成回文,多个字符可能有交叉的等同关系,那么有些字符最终都要是要变成同一个。这个是可以用并查集来做的,标程怕并不是所有人都知道并... 阅读全文
posted @ 2013-11-30 01:47 阿牧遥 阅读(288) 评论(0) 推荐(0)
摘要: http://community.topcoder.com/stat?c=problem_statement&pm=12725&rd=15702这题比较简单。首先所有的LR的顺序要一致,二来L和L,R和R的位置有限制关系。#include using namespace std;class FoxAndChess {public: string ableToMove(string begin, string target);};string FoxAndChess::ableToMove(string begin, string target) { int i = 0; in. 阅读全文
posted @ 2013-11-29 23:50 阿牧遥 阅读(212) 评论(0) 推荐(0)
摘要: http://community.topcoder.com/stat?c=problem_statement&pm=12746&rd=15703这道题有意思。给了树的根和每层节点的个数,求树的直径。做法是如果该层有两个节点,那么可能是有上有下,直径加二;如果该层只有一个节点,那么从这层开始,往下都只... 阅读全文
posted @ 2013-11-28 22:21 阿牧遥 阅读(215) 评论(0) 推荐(0)
摘要: http://community.topcoder.com/stat?c=problem_statement&pm=12758&rd=15704topcoder的题经常需要找规律,而不是蛮干。比如这题,一开始又陷入思维定势,想DP,还是枚举,都不太好。但仔细观察,拿数据尝试后发现,其实最终就是把球分... 阅读全文
posted @ 2013-11-28 21:08 阿牧遥 阅读(267) 评论(0) 推荐(0)
摘要: http://community.topcoder.com/stat?c=problem_statement&pm=12784真心觉得tc的div1 250不少好题,对我来说比较适合。这道题一开始拿到是个棋盘,觉得像是DP,然后觉得有些不同,因为棋盘不是满的,二来这可能是个判定问题,就是2种颜色够不... 阅读全文
posted @ 2013-11-26 23:27 阿牧遥 阅读(341) 评论(0) 推荐(0)
摘要: http://community.topcoder.com/stat?c=problem_statement&pm=12804&rd=15706首先A和B的长度都不一定一样,里面的元素也不一定有序。比如,A={1,4,6,7,2,8} and B={1,3,5,6,8,2,9,10}。二来,因为A和... 阅读全文
posted @ 2013-11-25 22:32 阿牧遥 阅读(211) 评论(0) 推荐(0)
摘要: http://community.topcoder.com/stat?c=problem_statement&pm=12822&rd=15707第一次用C++提交,艰辛。首先想到可以从尾往前扫,只有最后覆盖的颜色才有效;然后是想到用线段来做,用map记录线段;然后学到了lower_bound是找到元... 阅读全文
posted @ 2013-11-24 21:50 阿牧遥 阅读(201) 评论(0) 推荐(0)
上一页 1 ··· 14 15 16 17 18 19 20 21 22 ··· 43 下一页