
leetcode
文章平均质量分 65
秦时明月-cy
这个作者很懒,什么都没留下…
展开
-
gas_station——leetcode
class Solution {public: int canCompleteCircuit(vector &gas, vector &cost) { int len = gas.size(); int tank_all = 0; int pos = 0; int tank_cur =0; for (int i = 0; i < len; i++){ int tank原创 2014-09-04 15:35:53 · 657 阅读 · 0 评论 -
single number i
Given an array of integers, every element appears twice except for one. Find that single one.class Solution {//using xor bit manipulationpublic: int singleNumber(int A[], int n) {原创 2014-09-02 17:32:28 · 535 阅读 · 0 评论 -
Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.#include#include#includeusing namespace std;#define STOP system("pause")#if 0class Soluti原创 2014-09-02 17:27:01 · 675 阅读 · 0 评论 -
Copy List with Random Pointer -- LeetCode
#includeusing namespace std;#define STOP system("pause")struct RandomListNode { int label; RandomListNode *next, *random; RandomListNode(int x) : label(x), next(NULL), random(NULL) {}};class原创 2014-09-02 13:51:51 · 423 阅读 · 0 评论 -
Linked List Cycle [leetcode]
#include#include#includeusing namespace std; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} };class Solution {public: bool hasCycle(ListNod原创 2014-08-31 21:51:48 · 532 阅读 · 0 评论 -
★ Linked List Cycle II -- LeetCode
证明单链表有环路:本文所用的算法 可以 形象的比喻就是在操场当中跑步,速度快的会把速度慢的扣圈 可以证明,p2追赶上p1的时候,p1一定还没有走完一遍环路,p2也不会跨越p1多圈才追上 我们可以从p2和p1的位置差距来证明,p2一定会赶上p1但是不会跳过p1的 因为p2每次走2步,而p1走一步,所以他们之间的差距是一步一步的缩小,4,3,2,1,0 到0的时候就重合原创 2014-09-01 09:50:04 · 669 阅读 · 0 评论 -
*candy——leetcode
/* There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these c原创 2014-09-04 10:15:11 · 671 阅读 · 0 评论