leetcode做题记录
qq_35510981
这个作者很懒,什么都没留下…
展开
-
1. Two Sum 使用unsorted_map或者vector的sort函数
Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same e原创 2017-07-05 19:58:29 · 312 阅读 · 0 评论 -
101. Symmetric Tree镜像树
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3B原创 2017-07-06 18:27:12 · 150 阅读 · 0 评论 -
287. Find the Duplicate Number找环的起点
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, fin原创 2017-07-06 18:24:46 · 184 阅读 · 0 评论 -
13 12罗马数字和阿拉伯数字互相转换
一 罗马数字转阿拉伯数字 【罗马数字】 1~9: {“I”, “II”, “III”, “IV”, “V”, “VI”, “VII”, “VIII”, “IX”}; 10~90: {“X”, “XX”, “XXX”, “XL”, “L”, “LX”, “LXX”, “LXXX”, “XC”}; 100~900: {“C”, “CC”, “CCC”, “CD”, “D”, “DC”, “D原创 2017-07-06 18:22:26 · 1012 阅读 · 0 评论 -
415. Add Strings 计算两个数字字符串的和
Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2. Note: 1. The length of both num1 and num2 is < 5100. 2. Both num1 and num2 contains only dig原创 2017-07-06 18:15:36 · 256 阅读 · 0 评论 -
404. Sum of Left Leaves求树的所有左叶子节点的和
Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.原创 2017-07-06 18:08:17 · 235 阅读 · 0 评论 -
453. Minimum Moves to Equal Array Elements移动最小的步数使所有元素相等
Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1. Example: Input: [1,2,3]Output原创 2017-07-06 15:34:02 · 540 阅读 · 0 评论 -
455. Assign Cookies给小孩分配饼干
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a cook原创 2017-07-06 15:26:58 · 357 阅读 · 0 评论 -
136 Single Number 找到只出现一次的数
题目:给定一个数组,其中只有一个数出现一次,其余都出现两次,请在O(n)的时间内,不另外开辟内存,找到这个只出现一次的数。、 解答:每个数与自己进行异或,结果是0,0与任何数异或,还是这个数。因此将所有数取异或,结果就是只出现一次的数。class Solution {public: int singleNumber(vector<int>& nums) { int res原创 2017-07-06 15:21:52 · 213 阅读 · 0 评论 -
448 Find All Numbers Disappeared in an Array找到[1,n]内没有出现的数字
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] inclusive that do not appear in this array. Could原创 2017-07-06 15:17:45 · 200 阅读 · 0 评论 -
492 Construct the Rectangle给定矩形的面积计算符合要求的长和宽
Problem:给定一个矩形的面积,求这个矩形的长和宽,使得长大于宽,长宽都是整数且差最小。 Solution:从根号下面积开始逐渐递减,直到找到可整除的数。class Solution {public: vector<int> constructRectangle(int area) { int m=sqrt(area); vector<int> res原创 2017-07-06 14:16:07 · 677 阅读 · 0 评论 -
389 Find the Difference找到一个字符串t中出现但是s中没有出现的字符
[题目] Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at a random position. Find the letter that wa原创 2017-07-06 14:06:42 · 345 阅读 · 0 评论 -
371 Sum of Two Integers用位操作实现两个数的加法——递归
Write a function that adds two numbers. You should not use + or any arithmetic operators.这道题让我们实现两数相加,但是不能用加号或者其他什么数学运算符号,那么我们只能回归计算机运算的本质,位操作Bit Manipulation,我们在做加法运算的时候,每位相加之后可能会有进位Carry产生,然后在下一位计算时需原创 2017-07-06 13:28:25 · 282 阅读 · 0 评论 -
172. Factorial Trailing Zeroes计算n!末尾0的个数
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity.题目描述:给定一个整数n,返回n!(n的阶乘)数字中的后缀0的个数。考虑n!的质数因子。后缀0总是由质因子2和质因子5相乘得来的,如果我们可以计数2和原创 2017-07-06 12:07:05 · 203 阅读 · 0 评论 -
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 houses原创 2017-07-06 18:29:21 · 182 阅读 · 0 评论