leetcode
不停前进的灰熊君
菜鸟级
展开
-
leetcode1--Two Sum
题目:找出一个序列中和为指定数target的两个数,并返回下标。思路:采用map,遍历一遍,对每个遍历到的数a,查看target - a是否在序列中,注意target是自身的两倍,不可单独取自身。代码:class Solution {public: vector twoSum(vector& nums, int target) { map Hash;原创 2016-01-04 10:18:59 · 258 阅读 · 0 评论 -
leetcode2--Add Two Numbers
题目:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it原创 2016-01-04 16:33:12 · 242 阅读 · 0 评论 -
leetcode3--Longest Substring Without Repeating Characters
题目:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length i原创 2016-01-04 20:38:38 · 249 阅读 · 0 评论 -
leetcode7--Reverse Integer
题目:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321思路:就是注意正负号,把数字和符号分开,然后颠倒数字,判断是否在int类型可表示数范围内,若不在返回0。主要temp类型是long才能判断是否在int表示范围内代码:c原创 2016-01-05 09:56:25 · 215 阅读 · 0 评论 -
leetcode8--String to Integer (atoi)
题目:Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible原创 2016-01-05 14:19:34 · 278 阅读 · 0 评论