Leetcode - 299. Bulls and Cows
Leetcode - 299. Bulls and Cows
Leetcode - Count and Say
Leetcode - 36. Valid Sudoku
Leetcode - Path
Leetcode -
Leetcode - 55. Jump Game
Leetcode - 36. Valid Sudoku
Leetcode - 130. Surrounded Regions
Leetcode - 130. Surrounded Regions
24
使用 Python 的算术运算符和指定的数字 2、3、4、5构造一个表达式,使用所有的4个数字和3个运算符各一次,计算得到28,
1234567891011import randomnum = list(input().split(" "))notation = ['-', '+', '/', '*', '**','%']answer = ''while answer != 28: sign ...
騎士巡邏
回溯法:骑士巡逻。
123456789101112131415161718192021222324252627282930313233343536373839404142434445"""递归回溯法:叫称为试探法,按选优条件向前搜索,当搜索到某一步,发现原先选择并不优或达不到目标时,就退回一步重新选择,比较经典的问题包括骑士巡逻、八皇后和迷宫寻路等。"""import sysimport time ...
Leetcode - / Combinations
Leetcode - Combinations
Leetcode - 400. Nth Digit
Leetcode - 400. Nth Digit
Fibonacci
斐波拉切数列
斐波那契数列(Fibonacci sequence),又称黄金分割数列,是意大利数学家莱昂纳多·斐波那契(Leonardoda Fibonacci)在《计算之书》中提出一个在理想假设条件下兔子成长率的问题而引入的数列,所以这个数列也被戏称为"兔子数列"。斐波那契数列的特点是数列的前两个数都是1,从第三个数开始,每个数都是它前面两个数的和,形如:1, 1, 2, 3, 5, 8, 13 ...
进制转换
递归
将十进制转化为十以内的任意进制
document.querySelectorAll('.github-emoji')
.forEach(el => {
if (!el.dataset.src) { return; }
const img = document.createElement('img');
...
阶乘 | Factorial
12345678910111213141516171819202122232425262728## old index valueen_l = 1 factorial = 1## to calculate n factorialn = 1 ## iteration variableinvfactorial = 1 ## inverse of n factorial# while True:# ...
年份日期星期计算
子、丑、寅、卯、辰、巳、午、未、申、酉、戌、亥
阶乘 | Factorial
完美数又称为完全数或完备数,它的所有的真因子(即除了自身以外的因子)的和(即因子函数)恰好等于它本身。例如:6(6=1+2+36=1+2+36=1+2+3)和28(28=1+2+4+7+1428=1+2+4+7+1428=1+2+4+7+14)就是完美数。完美数有很多神奇的特性,有兴趣的可以自行了解。
1234567891011import mathfor num in range(1, 1000 ...
Prime
204. Count Primes[E]
https://leetcode.com/problems/count-primes/
Description
Count the number of prime numbers less than a non-negative number, *n*.
Example:
123Input: 10Output: 4Explanation: There ...
Sqrt
求根
首先我们需要定义一个floatrange:
12345678910111213141516171819def floatrange(start,stop,steps): ''' Computes a range of floating value. Input: start (float) : Start value. ...
Pascal's Triangle
杨辉三角
118. Pascal’s Triangle[E]
https://leetcode.com/problems/pascals-triangle/
Description
Given a non-negative integer numRows, generate the first numRows of Pascal’s triangle.
In Pascal’s trian ...
文本统计与词云制作
Text Analyzer
characterCount.py
其中的
1234if c in dic: dic[c]+=1else: dic[c]=1
我们也可以用dic[c] = dic.get(c, 0)+ 1 或者
12dic.setdefault(c, 0)ic[c] = dic[c] + 1
代替。
1234567891011121314151617181920filename = ...














