231. Power of Two
Question
Given an integer, write a function to determine if it is a power of two.
Solution
Approach #1 (count the number of 1) [Accepted]
Algorithm
Integer is a power of two means only one bit of n is '1', for example, 100 is 2^2=4 while 110 is 2^2+2^1=6.继续阅读 »
Typically, you only need to execute the following command for compiling project.
bash
xmake
xmake will probe your host environment and target platform automaticly.
The default mode is release and xmake will compile all targets.
You can compile only one given target which name is 'test' for executing the follo继续阅读 »
This article goes out to all those special people in my heart
Every person that matters the most,you know who you are
Does not matter for now,does not matter latter
All I gonna to do is make that call
Turn around,there you are
And so to you from the bottom of my heart,I wanna say one thing:Thank you继续阅读 »
Question
Given a linked list, remove the nth node from the end of list and return its head.
For example,
Given linked list: 1->2->3->4->5, and n = 2.
After removing the second node from the end, the linked list becomes 1->2->3->5.
Note:
Given n will always be valid.
Try to do this in one pass.
解说
这道题的意思是,如何反向删继续阅读 »
Question
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.
Example:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
UPDATE (2016/2/13):
The return forma继续阅读 »
直接写
js
function imgError(image) {
image.onerror = null; // prevent event bubble
image.src = "/images/noimage.gif";
return true;
}
html
使用 jQuery
```js
$("img").error(function () {
$(this).unbind("error").attr("src", "broken.gif");
});
//If you use this technique you can use the "one" method to av继续阅读 »
What Is Google C++ Mocking Framework?
When you write a prototype or test, often it's not feasible or wise to rely on real objects entirely. A mock object implements the same interface as a real object (so it can be used as one), but lets you specify at run time how it will be used and what it should do (which methods 继续阅读 »