[LeetCode C实现]292. 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 be the winner. You will take the first turn to remove the stones.

Both of you are very clever and have......

[LeetCode C实现]2. Add Two Numbers

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

You may assume the two numbers do not contain any leading zero, except the numb......

IO多路复用

I/O多路复用支持同时在多个文件描述符上阻塞,并在其中某个可以读写时收到通知。因此I/O多路复用成为应用的关键所在,在设计上遵循如下原则。

1.I/O多路复用:当任何一个文件描述符I/O就绪时进行通知

2.在有可用的文件描述符之前一直处于睡眠状态。

3.唤醒:哪个文件描述符可用了?

4.处理所有I/O就绪的文件描述符,没有阻塞。

5.返回第一步重新开始。

原版英文:

Multiplexed I/O allows an application to concurrently block on multiple file descriptors, and receive notifi......

[LeetCode C 实现]217. Contains Duplicate

Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.

最直接的思路,o(n*n)

bool containsDuplicate(int* nums, int numsSize)

{

for(int i=0;i<nums......

三个特殊的位

针对几个特殊的位,前几天与同事一起讨论,整理相关内容如下,以备复习之用。

实际用户ID(RUID):用于标识一个系统中的用户,一般是在登录之后,就被唯一确定的,就是登陆的用户的uid

有效用户ID(EUID):用于系统决定用户对系统资源的权限。也就是说当用户做任何一个操作时,最终看它有没有权限,都是在判断有效用户ID是否有权限,如果有,则OK,否则报错不能执行。在正常情况下,一个用户登录之后(我们假设是A用户),A用户的有效用户ID和实际用户ID是相同的,但是如果A用户在某些场景中想要执行一些特权操作,而上面我们说到用户的任何操作,LINUX内核都是通过检验有效用户ID来判断当前执行这个操......

[LeetCode C 实现]784. Letter Case Permutation

Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible strings we could create.

Examples:

Input: S = "a1b2"

Output: ["a1b2", "a1B2", "A1b2", "A1B2"]

......

[LeetCode C 实现]693. Binary Number with Alternating Bits

Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.

Example 1:

Input: 5

Output: True

Explanation:

The binary representation of 5 is: 101

Example 2:

Input: 7

Output: False

Explanation:

The binary representation ......

[编程珠玑]第一章:开篇

书中第一章给提出了一个如下排序问题:

输入:一个至多包含n个非负整数的文件,每个数都小于n; 且这些整数都不重复;数据之间也不存在关联关系。 此处n取值10000000。

约束:①最多1MB的内存空间可用;②磁盘空间充足;③运行时间最多几分钟, 最好是线性时间。

输出:按升序排列的整数序列。

位图排序

针对该题的特点,由于待排序的数据记录较多,如果使用常见的排序方法效率较低,而且内存空间有限(限制为1MB左右),不能一次性将数据如内存,需从文件中多次读入,该书引入了一种新的排序方法 ---位图法。

所谓位图法,就是使用一串二进制串来表示待排序列元素集合的方法。 比如,我们知......

[LeetCode C实现] 121. Best Time to Buy and Sell Stock

Say you have an array for which the ith element is the price of a given stock on day i.

If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.

Example 1:

Input:

Output: 5

max. differ......

[LeetCode C 实现]45. Jump Game II

Given an array of non-negative integers, you are initially positioned at the first index of the array.

Each element in the array represents your maximum jump length at that position.

Your goal is to reach the last index in the minimum number of jumps.

For example:

Given array A =

The minimum n......