摘要: 思路: 利用二分查找,分别查找待统计数字的头和尾的下标,最后做差加一即为结果。C++: 1 #include 2 #include 3 using namespace std; 4 5 int GetFirstK(vector& nums, int startpos, int endpos,... 阅读全文
posted @ 2015-07-12 16:44 tjuloading 阅读(142) 评论(0) 推荐(0)
摘要: Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: ... 阅读全文
posted @ 2015-07-12 16:08 tjuloading 阅读(155) 评论(0) 推荐(0)
摘要: Given a singly linked list, determine if it is a palindrome.思路: 用快慢指针找到链表中点,反转后半部分链表,然后与前半部分进行匹配,随后将链表恢复原状(本题没有这个要求,具体情况具体对待)。C++: 1 /** 2 * Definit... 阅读全文
posted @ 2015-07-12 14:54 tjuloading 阅读(173) 评论(0) 推荐(0)