算法学习
鬼谷中妖
努力成为一个合格的程序员
展开
-
排序算法和查找算法
文章目录冒泡排序冒泡排序冒泡排序function bubbleSort(arr) { let temp = null; for (let i = 0; i < arr.length; i++) { for (let j = i + 1; j < arr.length; j++) { if (arr[i] > arr[j]) { temp = arr[i] arr[i] = arr[j] arr[j] =原创 2022-03-01 00:17:52 · 323 阅读 · 0 评论 -
codewars算法题-求因子
算法要求 Create a function named divisors that takes an integer and returns an array with all of the integer’s divisors(except for 1 and the number itself). If the number is prime return the string ‘(int原创 2017-02-13 11:28:27 · 702 阅读 · 0 评论 -
codewars算法题-求两数组元素长度差值极大值
算法要求 You are given two arrays a1 and a2 of strings. Each string is composed with letters from a to z. Let x be any string in the first array and y be any string in the second array. Find max(abs(leng原创 2017-02-13 12:24:58 · 581 阅读 · 0 评论 -
codewars算法题-Sum without highest and lowest number
算法要求 Sum all the numbers of the array (in F# and Haskell you get a list) except the highest and the lowest element (the value, not the index!).(The highest/lowest element is respectively only one ele原创 2017-02-14 21:29:54 · 1217 阅读 · 0 评论 -
codewars算法题-Array.diff
算法要求: Your goal in this kata is to implement an difference function, which subtracts one list from another. It should remove all values from list a, which are present in list b. c方法,双重循环:funct原创 2017-02-14 21:36:39 · 862 阅读 · 0 评论 -
算法题-Array random element
算法要求: 生成一个数组,要求数组中的元素,是由a-zA-Z和构成,元素长度为3。 var alphaList = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";var arr =[];function createStr(){ var array =[]; for(var i=0; i<3; i++)原创 2017-03-21 10:08:55 · 280 阅读 · 0 评论 -
codewars算法题-酒局划拳
算法要求: 通过这个例子我终于明白划拳规则是什么了。 1. “拳”代表数字0,”布”代表数字5。猜中双方伸出的两只手所对应的数字和即为正确。 2. 如果某一方说的数字小于自己伸出的手代表的数字和或者减去自己伸出的数字和后大于10 ,则另一方赢。 eg:game([20,"Fist Fist"], [10,"Palm Palm"]);should return "B Win!"game([原创 2017-03-24 09:44:55 · 609 阅读 · 0 评论