leetcode
文章平均质量分 68
糊涂虫神探
三流本科造就的一流程序猿
展开
-
第一章 引论
练习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 · 397 阅读 · 0 评论 -
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 · 369 阅读 · 0 评论 -
由外向内生成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 · 421 阅读 · 0 评论 -
最大子序列和问题的解
关于最大子序列和问题的四种解法的实现,关于代码中的注释有时间会补加,欢迎各位指点,交流。原创 2014-12-25 22:26:52 · 372 阅读 · 0 评论 -
统计无符号整型数的二进制码中‘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 · 566 阅读 · 1 评论 -
杨辉三角 空间复杂度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 · 798 阅读 · 0 评论 -
字符串转成整数大数乘法
今天看到的题如下所示: 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 · 622 阅读 · 0 评论 -
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 · 306 阅读 · 0 评论 -
求两个整数最大公约数的欧几里德算法和求幂运算程序
求两个数最大公约数的欧几里德算法: /* *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 · 485 阅读 · 0 评论 -
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 · 359 阅读 · 0 评论