- 博客(11)
- 资源 (1)
- 收藏
- 关注
原创 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
2016-04-12 22:08:41
341
原创 Range Sum Query - Immutable(accepted版本)
在discuss里看到一位存在的算法,他的算法里的思想为我打开了另一扇门,传送门聪明人的解法. 下面是我实现的C语言版本。呵呵,大家见笑啦!看来提交不能通过的问题,自己还没有深入思考,改之! #include struct NumArray { int num; }; /** Initialize your data structure here. */ struct NumArra
2016-04-09 17:26:04
410
原创 Range Sum Query - Immutable
题目详细信息如下: Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. Example: Given nums = [-2, 0, 3, -5, 2, -1] sumRange(0, 2) -> 1 sumRange(2, 5)
2016-04-09 16:23:37
406
原创 字符串转成整数大数乘法
今天看到的题如下所示: Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. Subscribe to see which c
2016-04-07 23:38:19
692
原创 杨辉三角 空间复杂度O(k)
今天在leetcode上看到一题如下: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra spa
2016-04-06 22:40:48
856
原创 统计无符号整型数的二进制码中‘1’的个数
昨天在leetcode上看到一道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 the
2016-04-06 10:00:13
625
原创 由外向内生成N*N矩阵
前两天在线笔试时的一道题,生成一个N为的矩阵,形式如下N=3 1 2 3 8 9 4 7 6 5当时用下面的方法去写 结果总是出错,也不能debug,最终没调出来。考完后重新调了一下 不过觉得应该有更好的算法才对,可是想不出来,请大家多多指教。#includevoid gen_matrix(int n){ int i, j, tmp, count, arr[n][n]; i = j
2016-04-05 16:45:17
465
原创 求两个整数最大公约数的欧几里德算法和求幂运算程序
求两个数最大公约数的欧几里德算法: /* *Author: gyh *Date: 201412227 *Version: 1.0 */ #include int gcd(int a, int b); int main(void){ int a, b; printf("Entry two numbers: "); scanf("%d%d", &a, &b); printf(" %d and
2014-12-27 21:21:33
542
转载 Ubuntu14.04 英文版安装中文输入法
在英文版的Ubuntu14.04LTS系统上安装中文输入法过程: 联网状态下执行以下命令(在非root下首次执行时需要输入root密码): sudo apt-get install ibus 安装ibus输入法框架;该框架通常系统已经自带不用安装,若没有可通过该命令安装。 sudo apt-get install ibus-pinyin 安装pinyin输入法;给ibus输入法框架添
2014-12-16 13:39:28
1746
原创 第一章 引论
练习1.1 一个程序解决选择问题 /* For selecting kth number from n numbers. *Author: gyh *Date: 20141214 *Version: 1.0 */ #include void select(int n, int k){ int a[n]; printf("Enter %d numbers: ", n);
2014-12-15 16:39:49
430
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅