[LeetCode C实现]338. Counting Bits

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

贪心算法入门实例

在leetcode上刷题,学习了传说中的贪心算法,原理的话相对简单。在对动态规划有较深理解后再更新本文。

Leetcode中题目整理如下:

LeetCode C 实现 55. Jump Game

LeetCode C实现 455. Assign Cookies

[LeetCode C实现]455. Assign Cookies

Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a cookie that the child will be content with; and each cookie j has a size sj. If sj >= gi, we can ass......

[LeetCode C实现] 637. Average of Levels in Binary Tree

Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.

/**

* Definition for a binary tree node.

* struct TreeNode {

* int val;

* struct TreeNode *left;

* struct TreeNode *right;

* };

*/

/**

* Return an array of size *returnSize.

* No......

[LeetCode C实现]55. Jump Game

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.

Determine if you are able to reach the last index.

For example:

A = [2,3,1,1,4], return true.

A = [3,2,1,0,4], r......

动态规划入门实例

在leetcode上刷题,学习了传说中的动态规划,原理的话相对简单。可以参考如下链接,阅读之后可以对动态规划有个大概的认识。在对动态规划有较深理解后再更新本文。漫画趣谈:什么是动态规划

Leetcode中题目整理如下:

LeetCode C实现 70. Climbing Stairs

LeetCode C 实现198. House Robber

[LeetCode C 实现]198. House Robber

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses......

[LeetCode C实现]496. Next Greater Element I

You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums2.

The Next Greater Number of a number x in nums1 is the first greater number to its right in nu......

close-on-exec标志解析

close-on-exec标志的作用是使得文件描述符自动关闭,如果fork子进程之后子进程要执行exec*(),如果不设置close-on-exec标志会导致文件描述符没有关闭。

实例:parent.c

#include <fcntl.h>

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <string.h>

#include <sys/types.h>

#include <sys/wait.h>

int main()......

[LeetCode C实现] 263.Ugly Number

Write a program to check whether a given number is an ugly number.

Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7.

Note:

1 is typically treated as an ugly number.

Input ......