Leetcode
锦堇年
NLP学弱
展开
-
Leetcode(1)-happy数
A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equa原创 2015-12-25 16:32:35 · 337 阅读 · 0 评论 -
Leetcode(6) - easy
7.Reverse Integer My Submissions Question Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 求解如下:public class Solution { public int reverse(int x) {原创 2016-03-02 13:47:17 · 255 阅读 · 0 评论 -
Leetcode(8)-medium2
92, 134, 136, 141, 142, 152, 153\92.Reverse Linked List II Reverse a linked list from position m to n. Do it in-place and in one-pass. 把[m,n]那一段reverse之后再拼回去。134.Gas Station http://www.cnblogs.com/f原创 2016-03-09 17:04:50 · 369 阅读 · 0 评论 -
Leetcode(2) -Contains Duplicate
217.class Solution { public: bool containsDuplicate(vector<int>& nums) { map<int, int> int_map; for (int i = 0; i<nums.size(); i++) { if(int_map.count(nums[i])){原创 2016-02-15 16:59:49 · 272 阅读 · 0 评论 -
Leetcode(5)-Add two numbers
2 Add two numbers 模拟手工加和的过程即可,结构体中提供了构造函数;需要注意的是两个链表可能不等长,需要分别处理剩下的位数,还有最高位加和可能存在进位也需处理。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * Lis原创 2016-02-28 09:12:00 · 277 阅读 · 0 评论 -
Leetcode(3)-Summary Ranges
228 Summary Ranges For example, given [0,1,2,4,5,7], return [“0->2”,”4->5”,”7”].class Solution { public: string format(int begin, int end) { char buffer[32]; if (end == b原创 2016-02-15 17:17:47 · 299 阅读 · 0 评论 -
Leetcode(7) - medium1
11, 16, 24, 39, 43, 50, 6911.Container With Most Water My Submissions QuestionGiven n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are draw原创 2016-03-02 17:18:30 · 326 阅读 · 0 评论 -
Leetcode(4)-Two Sum
1.Two Sum 简单的想法就是遍历,尝试之后发现没有超时。有趣的是,题中没有提及但实际输入中存在负数,所以不能使用if(nums[i] > target) continue;剪枝class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> result;原创 2016-02-26 10:00:10 · 286 阅读 · 0 评论