
leetcode
leisurehippo
这个作者很懒,什么都没留下…
展开
-
Nim Game
题目如下: You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will原创 2016-09-08 23:12:55 · 177 阅读 · 0 评论 -
Sum of Two Integers
题目如下: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. 不让用加号或者减号,自然想到了一些逻辑操作,与或非,异或等等。一位数相加无非是四种可能 a b a+b 0 0 0 0 1 1 1 0 1 1原创 2016-09-11 16:06:44 · 255 阅读 · 0 评论 -
Single Number
题目如下: Given an array of integers, every element appears twice except for one. Find that single one. 考虑怎么能把一个数组中两个相同的数字“消”掉呢? N^N=0 也就是异或。而0^N=N,那么将数组中的数字全部异或最后剩下的数就是答案,算法如下:public class Solution {原创 2016-09-11 16:35:50 · 228 阅读 · 0 评论 -
Add Digits
题目如下: Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only o原创 2016-09-11 23:21:13 · 211 阅读 · 0 评论 -
Two Sum
问题描述: 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.如果简单的遍历两次数组,时间复杂度过大。 一个原创 2016-09-07 00:03:56 · 230 阅读 · 0 评论 -
Reverse String
题目如下: Write a function that takes a string as input and returns the string reversed. Example: Given s = “hello”, return “olleh”. 基本思路就是将字符串转成数组再逆序拼接成字符串。但是如果用String存储字符串耗时很大。String对象是不可改变的。每次使用 Syste原创 2016-09-08 22:16:41 · 247 阅读 · 0 评论