摘要: Given an arraynums, there is a sliding window of sizekwhich is moving from the very left of the array to the very right. You can only see theknumbers ... 阅读全文
posted @ 2015-07-18 15:03 tjuloading 阅读(207) 评论(0) 推荐(0)
摘要: Given an array ofnintegers wheren> 1,nums, return an arrayoutputsuch thatoutput[i]is equal to the product of all the elements ofnumsexceptnums[i].Solv... 阅读全文
posted @ 2015-07-16 15:06 tjuloading 阅读(485) 评论(0) 推荐(0)
摘要: Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is1 -> 2 -> 3 -> ... 阅读全文
posted @ 2015-07-15 16:08 tjuloading 阅读(694) 评论(0) 推荐(0)
摘要: Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to thedefinition of LCA on Wikipedia: “The lowest ... 阅读全文
posted @ 2015-07-15 16:01 tjuloading 阅读(158) 评论(0) 推荐(0)
摘要: 思路: 利用位运算C++: 1 #include 2 using namespace std; 3 4 int main() 5 { 6 int a = 11, b = 17; 7 int sum, carry; 8 do 9 {10 sum =... 阅读全文
posted @ 2015-07-14 14:04 tjuloading 阅读(111) 评论(0) 推荐(0)
摘要: 思路: 利用二分查找,分别查找待统计数字的头和尾的下标,最后做差加一即为结果。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 阅读(141) 评论(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 阅读(153) 评论(0) 推荐(0)
摘要: Given a singly linked list, determine if it is a palindrome.思路: 用快慢指针找到链表中点,反转后半部分链表,然后与前半部分进行匹配,随后将链表恢复原状(本题没有这个要求,具体情况具体对待)。C++: 1 /** 2 * Definit... 阅读全文
posted @ 2015-07-12 14:54 tjuloading 阅读(171) 评论(0) 推荐(0)
摘要: 只包含因子2、3、5的数称作丑数。 1 #include 2 #include 3 using namespace std; 4 5 int GetUglyNumber(int n) 6 { 7 if(n UglyNum(n, 0);11 UglyNum[0] = 1;12 ... 阅读全文
posted @ 2015-07-09 21:13 tjuloading 阅读(159) 评论(0) 推荐(0)
摘要: 输入一颗二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。C++: 1 #include 2 using namespace std; 3 4 struct TreeNode 5 { 6 int val; 7 TreeNode *left; 8 TreeNode *... 阅读全文
posted @ 2015-07-08 21:15 tjuloading 阅读(133) 评论(0) 推荐(0)