![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
bombSKLK
一步一脚印。
展开
-
leetcode-First Bad Version
bool isBadVersion(int version); class Solution { public: int firstBadVersion(int n) { if (n return -1; } int start = 1, end = n; int mid; while (start + 1 mid = start + (end - start) /原创 2015-09-25 18:32:18 · 347 阅读 · 0 评论 -
LeetCode-213. House Robber II
Note: This is an extension of House Robber. After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time原创 2016-04-25 15:21:33 · 400 阅读 · 0 评论 -
Leetcode-198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house原创 2016-04-25 13:40:11 · 363 阅读 · 0 评论 -
LeetCode-linked-list-cycle-ii
题目:如果一个链表循环,返回第一个进入循环的点,否则返回NULL。 class Solution { public: ListNode *detectCycle(ListNode *head) { if(head==NULL || head->next==NULL) return NULL; ListNode* pslow原创 2016-03-21 10:23:02 · 336 阅读 · 0 评论 -
LeetCode-Binary Tree Postorder Traversal
题目:很正常的二叉树后序遍历。 用递归调用非常快速。 class Solution { public: std::vector v; vector postorderTraversal(TreeNode *root) { poserorder(root); return v; } void poserorder(TreeNode *原创 2016-03-19 14:06:03 · 301 阅读 · 0 评论 -
LeetCode-max-points-on-a-line
这个问题是求在一个平面上,共线最多的点的个数。 本文参考了@一个健忘症患者的记忆备份 的博客,地址为http://blog.csdn.net/liushu1231/article/details/19839645 技能get: 1.map的使用 2.iterator的使用。用iterator对map对象的find,insert的操作都很有用。原创 2016-03-18 20:27:02 · 266 阅读 · 0 评论 -
LeetCode- Evaluate Reverse Polish Notation
题目: Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. 数学表达式的 逆式波兰记法。 答案:原创 2016-03-17 21:28:56 · 357 阅读 · 0 评论 -
LeetCode minDepth of 2 bin tree
111. Minimum Depth of Binary Tree 题目:Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf n原创 2016-03-17 19:21:25 · 338 阅读 · 0 评论 -
LeetCode-Contains Duplicate III
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i an原创 2015-10-11 11:39:41 · 377 阅读 · 0 评论 -
LeetCode-Contains Duplicate II
Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k.原创 2015-10-10 19:09:42 · 306 阅读 · 0 评论 -
LeetCode-Move Zeroes
class Solution { public: void moveZeroes(vector& nums) { int pos = 0; // 将非0数字都尽可能向前排 for(int i = 0; i < nums.size(); i++){ if(nums[i] != 0){原创 2015-09-25 18:36:14 · 306 阅读 · 0 评论 -
LeetCode-Contains DuplicateI
class Solution { public: bool containsDuplicate(vector& nums) { sort(nums.begin(),nums.end()); for (int i = 1; i < nums.size(); ++i) { if (nums[i] == nums[i - 1]) { return 1; } }原创 2015-09-25 19:52:06 · 404 阅读 · 0 评论 -
LeetCode-338. Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array. Example: For num = 5原创 2016-04-24 22:53:31 · 344 阅读 · 0 评论