- 博客(15)
- 资源 (2)
- 收藏
- 关注
原创 阶乘的长度-斯特林近似
阶乘的长度-斯特林近似斯特林公式(Stirling’s approximation)是一条用来取n的阶乘的近似值的数学公式。一般来说,当n很大的时候,n阶乘的计算量十分大,所以斯特林公式十分好用,而且,即使在n很小的时候,斯特林公式的取值已经十分准确。hdu 1018 Big NumberProblem DescriptionIn many applications very large integ
2016-09-22 14:19:23
724
原创 我在LeetCode的100题
我在LeetCode上面AC的只有94题,但是我思考的题目已经超过100题了。100题,我依然是菜鸟,不过算是入门了。我想回忆一下,算是总结与分享。一.我的小小经验 很幸运一开始和师兄一起训练,如果不是的话我觉得很难坚持一下,因为我自己做题的话是不可能一道题做一个小时的。我觉得一道题思考这么长时间是有它的收获的,现在我也慢慢练习在一个人的情况下思考尽可能长的时间。相信我,思考的时间与收获成正比。 模
2016-06-24 22:32:42
778
原创 gdb入门命令
gdb入门命令 这是gdb的入门指令,我本人也是新手,想通过写博客来提高自己的能力,希望能帮助到有需要的人,也希望有人可以指导。 我觉得学习gdb就要多练,不练的话话很快就会忘记那些命令,所以在这里列出这些命令是想大家一起,遇到想知道的命令就去谷歌。 简单命令一: start:停在main函数后的第一条语句; b (break):b+行号或者函数名,设置断点; r (run):运行函数,如
2016-06-01 22:22:05
448
转载 C语言 sizeof 运算符
今天看了一篇文章叫《C/C++刁钻问题各个击破之细说sizeof》,然后自己想写一写。 sizeof的作用: 1.求基本类型和复合类型所占的内存字节数 如:sizeof(int)、sizeof(int *) 2.求某个变量或者常量所占的内存字节数 如:int i; sizeof(i) sizeof(5) sizeof(5L)
2016-05-08 22:12:42
956
原创 LeetCode 338. Counting Bits C语言
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 yo
2016-04-28 20:58:51
746
原创 LeetCode 171. Excel Sheet Column Number C语言
Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 这一体是其他进制转换为进
2016-04-24 21:19:56
391
原创 LeetCode 242. Valid Anagram C语言
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. 首先是要两个字符串的长度想等; 然
2016-04-24 21:00:44
544
原创 LeetCode 100. Same Tree C语言
Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. 树的问题最容易想到的
2016-04-24 20:55:51
798
原创 LeetCode 237. Delete Node in a Linked List C语言
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value
2016-04-24 20:44:17
448
原创 LeetCode 283. Move Zeroes C语言
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. For example, given nums = [0, 1, 0, 3, 12], after calling your
2016-04-24 20:33:42
315
原创 LeetCode 226. Invert Binary Tree C语言
树大都用了递归的思想,这到题也是; 一颗只有根节点和叶子的二叉树,转置它是左右子树交换; 左右子树转置又是这样,这样就是自己调用自己了; 然后还要有递归的出口,当没有儿子的时候或者根节点为空时,返回自己,这个就是出口; /** * Definition for a binary tree node. * struct TreeNode { * int val; *
2016-04-24 20:16:28
574
原创 LeetCode 104. Maximum Depth of Binary Tree C语言
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 这到题最容易想出的方法是递归 递归就是自己调用自己,数的子树又
2016-04-24 20:05:58
466
原创 LeetCode 258. Add Digits C语言
最朴素的方法,也是可以AC 的方法是循环,但是不符合题目要求 int addDigits(int num) { return (num-1)%9+1; } 时间复杂度是O(1),我们应该最先想到找规律。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 答案为1-9中的一个,且循
2016-04-24 19:50:50
431
原创 LeetCode 292. Nim Game C语言
这到题代码很简单,要讲清楚不容易,最简单的是找规律,但是这还没讲出它的道理,等你们解释给我听。bool canWinNim(int n) { if(n%4==0) return 0; else return 1; }
2016-04-24 19:44:14
355
原创 LeetCode 344. Reverse String C语言
这道题很简单,前后两个“指针”,一个前移,一个后移。 ``` char* reverseString(char* s) { int i=0,j=strlen(s)-1; char t; while(i { t=s[i]; s[i]=s[j]; s[j]=t; i++;
2016-04-24 19:31:54
937
无锁化编程
2018-07-11
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人