[LeetCode C实现] 728. Self Dividing Numbers

A self-dividing number is a number that is divisible by every digit it contains.

For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.

Also, a self-dividing number is not allowed to contain the digit zero.

Given a lower and upper number bound, output a l......

[LeetCode C 实现]342. Power of Four

Given an integer (signed 32 bits), write a function to check whether it is a power of 4.

Example:

Given num = 16, return true. Given num = 5, return false.

Follow up: Could you solve it without loops/recursion?

bool isPowerOfFour(int num)

{

return !(num & (num - 1)) && (num & 0......

[LeetCode C 实现]572. Subtree of Another Tree

Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this node's descendants. The tree s could also be considered as a subtree of itself.

递归实现,代码有点美😄

/**

*......

[LeetCode C 实现]268. Missing Number

Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.

Example 1

Input:

Output: 2

Example 2

Input:

Output: 8

一个“简单”的问题,深思之后似乎并没有那么简单。

最开始的版本:

int missingNumber(int* nums, int numsSize)

{

int sum = 0;

sum = numsSize *(n......

[LeetCode C 实现]231.Power of Two

Given an integer, write a function to determine if it is a power of two.

我的常规解法:对于INT_MIN的话是-2147483648的话恰好也满足二进制位中只有一个1的情况,因此应该排除,然后统计n中1的个数, 如果为1则返回true;

bool isPowerOfTwo(int n)

{

if(INT_MIN == n)

return false;

int cnt = 0;

while(n)

{

n = n &(n-1);

cnt++;

}

return (cnt ==1 )? true:false......

[LeetCode C 实现]389. Find the Difference

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 was added in t.

Input:

s = "abcd"

t = "abcde"

Output:

e

Explanation:

'e......

[LeetCode C实现]500.Keyboard Row

Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.

int insameline(char *str, int *hash)

{......

[LeetCode C实现]24.Swap Nodes in Pairs

Given a linked list, swap every two adjacent nodes and return its head.

For example,

Given 1->2->3->4, you should return the list as 2->1->4->3.

Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.

/*......

[LeetCode C实现]476.Number Complement

Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.

Note:

The given integer is guaranteed to fit within the range of a 32-bit signed integer.

You could assume no leading zero bit in the integer’s binary representatio......

[LeetCode C实现]237. Delete Node in a Linked List

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.

Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 -> 4 after calling your function.

这道题有一个限制......