算法
melo_fang
与自己能力相等的才叫机会
展开
-
n个集合的交集 并集关系
最近刷CODEWARS遇到一道题,特地找了下集合相关的知识,记录下。I(AUB) = I(A) + I(B) - I(AnB)I(AUBUC) = I(A) + I(B) + I(C) - (I(AnB)+I(AnC)+I(BnC)) + I(AnBnC)n个集合的并集(容斥原理公式)n(A1∪A2∪...∪Am)=∑n(Ai)1≤i≤m - ∑n(Ai∩Aj)1≤i≤j≤m + ∑n(Ai...原创 2018-03-13 11:34:19 · 10565 阅读 · 0 评论 -
CODEWARS_个人记录(1)
4 kyu题目:String MIX描述:Given two strings s1 and s2, we want to visualize how different the two strings are. We will only take into account the lowercase letters (a to z). First let us count the frequenc...原创 2018-04-17 18:02:20 · 465 阅读 · 1 评论 -
CODEWARS_个人记录2
4 kyu题目:Roman Numerals EncoderDESCRIPTION:Create a function taking a positive integer as its parameter and returning a string containing the Roman Numeral representation of that integer.Modern Roman...原创 2018-04-17 18:08:33 · 431 阅读 · 1 评论 -
数据结构学习笔记-BubbleSort 冒泡排序
这个课程对BubbleSort的优化指明了一个方向, 即如果有这么一个数组 5,3,4,2,7,6,1,9,10,11,12,13 那么实际上后面的一段9,10,11,12,13已经处于就位的状态,我们可以考虑从这种情况对算法进行优化下面是我根据这个思路整理的C代码:int bubbleSort(int *ptr, int len){ int i; int last; int...原创 2018-04-25 10:43:07 · 179 阅读 · 0 评论 -
CODEWARS_个人记录3
4 kyu题目:Factorial tail (阶乘的尾巴)总结一下要求是求出Num的阶乘在base进制下尾部0的个数num的范围是1-1‘000‘000base的范围是2-256 题目给出了一个模板解法// fixmeint zeroes (int base, int number) { int factorial, trailingzeroes = 0;...原创 2018-10-12 11:34:46 · 314 阅读 · 0 评论 -
leetcode [240] 搜索二维矩阵 II
编写一个高效的算法来搜索mxn矩阵 matrix 中的一个目标值 target。该矩阵具有以下特性:每行的元素从左到右升序排列。 每列的元素从上到下升序排列。示例:现有矩阵 matrix 如下:[ [1, 4, 7, 11, 15], [2, 5, 8, 12, 19], [3, 6, 9, 16, 22], [10, 13, 14, ...原创 2019-03-21 17:22:34 · 110 阅读 · 0 评论