[LeetCode C 实现]557. Reverse Words in a String III

Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.

Example 1:

Input: "Let's take LeetCode contest"

Output: "s'teL ekat edoCteeL tsetnoc"

void reverse(int start,int en......

[LeetCode C实现] 242. Valid Anagram

Given two strings s and t, write a function to determine if t is an anagram of s.

For example,

s = "anagram", t = "nagaram", return true.

s = "rat", t = "car", return false.

Note:

You may assume the string contains only lowercase alphabets.

Foll......

标准库函数qsort使用误区

问题要从刷leetcode说起350. Intersection of Two Arrays II,在使用标准库函数qsort对数组进行排序,然后对两个已排序的数组求出其共有部分,可是提交后发现存在一个用例不过,截图如下:

完整提交代码如下:

int compare (const void * a, const void * b)

{

ret......

unsigned char与signed char区别

今天有同事问我unsigned char与char有啥区别,我结合自己的理解与前段时间看的深入理解计算机系统一书进行总结。

首先signed char与unsigned char都占一个字节,但是他们表示的数据范围不同,unsigned char 范围[0-255],signed char的范围是[-128 127],char的范围也是[-128,127].验证程序如下:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

typedef unsigned char * byte_p......

printf格式控制

本文记录在学习linux c编程中遇到的printf相对新奇少见的用法,常见用法在此不一一罗列。

/* Listing 12-1 */

#include <fcntl.h>

#include "tlpi_hdr.h"

#define MAX_LINE 100

int

main(int argc, char *argv[])

{

int fd;

char line[MAX_LINE];

ssize_t n;

fd = open("/proc/sys/kernel/pid_max", (argc > 1) ? O_RDWR : ......

[LeetCode C 实现]561. Array Partition I

Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possible.

Example:

Input:

Output: 4

Explanation: n is 2, and the maximum sum of pairs is 4 = min(1,......

浅谈回调函数

浏览知乎看到有人问如何理解回调函数阅读了部分回答,结合维基百科的例子总结如下。

知乎上赞同数最多的回答者的答案是:

你到一个商店买东西,刚好你要的东西没有货,于是你在店员那里留下了你的电话,过了几天店里有货了,店员就打了你的电话,然后你接到电话后就到店里去取了货。在这个例子里,你的电话号码就叫回调函数,你把电话留给店员就叫登记回调函数,店里后来有货了叫做触发了回调关联的事件,店员给你打电话叫做调用回调函数,你到店里去取货叫做响应回调事件。回答完毕。

正常情况下比如简单的函数:int max(int a, int b);

要使用这函数,得到两者最大的值, 外面就要传进来 a, b。这个......

[LeetCode C实现] 349. Intersection of Two Arrays

Given two arrays, write a function to compute their intersection.

Example:

Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].

Note:

Each element in the result must be unique.

The result can be in any order.

/**

* Return an array of size *returnSize.

* Note: The returned array must be mal......

[LeetCode C 实现]19. Remove Nth Node From End of List

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 ......

[LeetCode C 实现]344. Reverse String

Write a function that takes a string as input and returns the string reversed.

Example:

Given s = "hello", return "olleh".

char* reverseString(char* s)

{

char tmp;

int end = strlen(s) - 1;

int start = 0;

while(start < end)

{

tmp = s[start];

s[start++] = s[end];

s[end--] =......