Skip to content

Instantly share code, notes, and snippets.

View yun77op's full-sized avatar
🏠
Working from home

yun77op yun77op

🏠
Working from home
View GitHub Profile
@yun77op
yun77op / countMaxOfArray.js
Created March 26, 2020 15:19
给定⼀个整数数组 a,实现⼀个函数 countMax(a) ,计算出从 a 中选择出多个不相邻元素组成最⼤的 和是多少。
function Solution(array) {
const dp = new Array(array.length);
dp[0] = [];
dp[0][0] = 0;
dp[0][1] = array[0];
let max = 0;
for (let i = 1; i < array.length; ++i) {
@yun77op
yun77op / guess.js
Created April 15, 2018 13:29
猜数字游戏
/*
有一个猜数字游戏,庄家预先写下一个四位数字(每位数字各不相同),玩家每次随机猜一个数字,庄家告知玩家猜对了几A几B(A代表数字和位置都相同,B代表包含该数字但位置不同,比如如果庄家写的是3514,玩家猜的是3165,庄家会回答1A2B),玩家继续猜,直到猜中为止。如果超过5轮没猜中,则玩家输,否则玩家赢。
请为玩家设计一个猜数字的算法,确保玩家能够大概率胜。
*/
// 返回数字和位置都相同的个数
const calcStrictIdentical = (target, input) => {
let count = 0;
$simsun-font-family: arial,\5b8b\4f53;
$yahei-font-family :"Microsoft YaHei",\5fae\8f6f\96c5\9ed1,arial,\5b8b\4f53;
body {
line-height: 1.5;
}
h1 {
font-size: 3em;