ZMR小站

很高兴遇见你~


  • 首页

  • 标签

  • 分类

  • 归档

p258

发表于 2016-05-11 | 分类于 blog

LeetCode P258 Add Digits 题解

1.题目:

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 one digit, return it.

Follow up:
Could you do it without any loop/recursion in O(1) runtime?

题意:

输入一个数字,将这个数字所有位数相加一直到得到一个小于10的数,返回这个数
希望复杂度为O(1)

阅读全文 »

p136

发表于 2016-05-11 | 分类于 blog

LeetCode P136 Single Number 题解

1.题目:

Given an array of integers, every element appears twice except for one. Find that single one.

Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

Subscribe to see which companies asked this question

题意:

输入一个数组,返回这个数组中单出来的那个数,希望只做一次循环不占用其它空间

阅读全文 »

常用转换

发表于 2016-05-11 | 分类于 blog

String 与 int

1). int i = Integer.parseInt([String]);
int i = Integer.parseInt([String],[int radix]);

2). int i = Integer.valueOf(my_str).intValue();

p292

发表于 2016-05-11 | 分类于 blog

LeetCode P292 Nim Game 题解

1.题目:

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 be the winner. You will take the first turn to remove the stones.

Both of you are very clever and have optimal strategies for the game. Write a function to determine whether you can win the game given the number of stones in the heap.

For example, if there are 4 stones in the heap, then you will never win the game: no matter 1, 2, or 3 stones you remove, the last stone will always be removed by your friend.

阅读全文 »

鼎沸

发表于 2016-05-08 | 分类于 life

鼎沸

主题片集(请在PC端或WIFI下浏览)

阅读全文 »

资源

发表于 2016-05-08 | 分类于 other

Android UI性能优化详解

http://mrpeak.cn/android/2016/01/11/android-performance-ui

p338

发表于 2016-05-08 | 分类于 blog

LeetCode P338 Counting Bits 题解

1.题目:

Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.

Example:
For num = 5 you should return [0,1,1,2,1,2].

Follow up:
It is very easy to come up with a solution with run time O(n*sizeof(integer)). But can you do it in linear time O(n) /possibly in a single pass?
Space complexity should be O(n).
Can you do it like a boss? Do it without using any builtin function like __builtin_popcount in c++ or in any other language.

阅读全文 »
1…313233
ZhangMengRou

ZhangMengRou

ZMR小站

230 日志
4 分类
14 标签
© 2019 ZhangMengRou
由 Hexo 强力驱动
|
主题 — NexT.Gemini v5.1.4