随笔分类 -  Leetcode

摘要:/* Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100 */ class Solution { public: string add 阅读全文
posted @ 2016-03-10 11:42 向日葵的祈愿 阅读(356) 评论(0) 推荐(0)
摘要:筛法计算素数: class Solution { public: int countPrimes(int n) { vector<bool> isprime(n, true); isprime[0] = false; isprime[1] = false; for (int i = 2; i < s 阅读全文
posted @ 2016-03-10 00:55 向日葵的祈愿 阅读(218) 评论(0) 推荐(0)
摘要:Sort a linked list in O(n log n) time using constant space complexity. 链表的归并排序。 /** * Definition for singly-linked list. * struct ListNode { * int val 阅读全文
posted @ 2016-03-08 23:51 向日葵的祈愿 阅读(200) 评论(0) 推荐(0)
摘要:Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: A: a1 → a2 阅读全文
posted @ 2016-03-08 00:28 向日葵的祈愿 阅读(225) 评论(0) 推荐(0)
摘要:题目描述: /*Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two e 阅读全文
posted @ 2016-03-03 00:40 向日葵的祈愿 阅读(245) 评论(0) 推荐(0)
摘要:class Solution { public: int myAtoi(string str) { if (str == "") return 0; //判断是否为空 int i = 0, sign = 1; long long sum = 0; //用long long来存结果,易于判断是否溢出, 阅读全文
posted @ 2016-03-01 11:40 向日葵的祈愿 阅读(173) 评论(0) 推荐(0)