2018年2月6日

leetcode 237. Delete Node in a Linked List

摘要: 由于题目已经限定范围,直接覆盖即可。 阅读全文

posted @ 2018-02-06 17:18 willaty 阅读(85) 评论(0) 推荐(0) 编辑

leetcode 234. Palindrome Linked List

摘要: 快慢指针找到中点,反转后半段,比较。 其实慢指针走的时候就可以开始反转。 阅读全文

posted @ 2018-02-06 14:20 willaty 阅读(103) 评论(0) 推荐(0) 编辑

leetcode 232. Implement Queue using Stacks

摘要: class MyQueue { public: /** Initialize your data structure here. */ stack r, b; MyQueue() { } /** Push element x to the back of queue. */ void push(int x) { ... 阅读全文

posted @ 2018-02-06 13:12 willaty 阅读(79) 评论(0) 推荐(0) 编辑

leetcode 231. Power of Two

摘要: bool isPowerOfTwo(int n) { if (n < 1) return false; int m = 1; for (int i = 0; i < 32; i++) { int j = n & m; if (j == n) return tru... 阅读全文

posted @ 2018-02-06 11:50 willaty 阅读(72) 评论(0) 推荐(0) 编辑

leetcode 226. Invert Binary Tree

摘要: TreeNode* invertTree(TreeNode* root) { if (root == NULL) return NULL; auto temp = root->left; root->left = root->right; root->right = temp; invert... 阅读全文

posted @ 2018-02-06 11:27 willaty 阅读(78) 评论(0) 推荐(0) 编辑

leetcode 225. Implement Stack using Queues

摘要: 可以用两个队列倒来倒去,保留最后一个,pop效率成了线性的。 我这里用一个队列,自己倒自己,pop和top都是线性,时间换空间吧。 阅读全文

posted @ 2018-02-06 11:23 willaty 阅读(82) 评论(0) 推荐(0) 编辑

leetcode 219. Contains Duplicate II

摘要: 哈希,注意第一个为0的情况。 阅读全文

posted @ 2018-02-06 11:01 willaty 阅读(80) 评论(0) 推荐(0) 编辑

leetcode 217. Contains Duplicate

摘要: 哈希一下即可。 阅读全文

posted @ 2018-02-06 09:58 willaty 阅读(76) 评论(0) 推荐(0) 编辑

leetcode 206. Reverse Linked List

摘要: 头插法,每次取出后插入新链表的头部。 阅读全文

posted @ 2018-02-06 09:49 willaty 阅读(66) 评论(0) 推荐(0) 编辑

导航