博客
关于我
codewars练习(javascript)-2021/5/6&7&8&9&10
阅读量:740 次
发布时间:2019-03-22

本文共 1153 字,大约阅读时间需要 3 分钟。

codewars-js练习

2021/5/6

【1】<7kyu>【Greatest common divisor】

求两个正整数的最大公约数

整数可以很大,所以你需要找到一个聪明的解决方案。

思路

一开始采用了简单粗暴的方式(代码如下),然后时间超时。

function mygcd(x, y) {    var i = Math.min(x, y);    var temp = [];    if (x == 1 && y == 1) return 1;    while (i >= 1) {        if (x % i == 0 && y % i == 0) return i;        i--;    }}
解决方法

后来采用了下面的辗转相除法,就通过了。

##### 原理如果有两个数a和b,b为0,那么a和b的最大公约数一定是a。那么就想尽办法让它出现0的情况。### 2021/5/7【1】<7kyu>【Sum of Triangular Numbers】#### 返回包括第n个三角形数在内的所有三角形数的和。##### 示例[01] 02 [03] 04 05 [06] 07 08 09 [10] 11 12 13 14 [15] 16 17 18 19 20 [21] 如果输入4,则返回1 + 3 + 6 + 10 = 20。##### 解决方法```javascript

2021/5/8

【1】<7kyu>【Invisible cubes】

问题描述

给定的n对应的不可见立方体数。

示例

输入:0输出:0输入:2输出:27

解决方法

【2】<6kyu>【Arabian String】

创建一个可以将字符串从不同格式转换为PascalCase的方法。这也必须支持符号。

示例

"example name" → "ExampleName""your-NaMe-here" → "YourNameHere""testing ABC" → "TestingAbc"

解决方法

2021/5/9

【1】<8kyu>【What’s the real floor?】

写一个函数,在美国系统中给定的楼层返回在欧洲系统中的楼层。

示例

1 → 02 → 0513 → 41514 → 13-316 → -3

解决方法

2021/5/10

【1】<8kyu>【Multiplication table for number】

返回一个从1到10的整数的乘法表。

示例

1 * 5 = 52 * 5 = 103 * 5 = 154 * 5 = 205 * 5 = 256 * 5 = 307 * 5 = 358 * 5 = 409 * 5 = 4510 * 5 = 50

解决方法

转载地址:http://oxdwk.baihongyu.com/

你可能感兴趣的文章
NLP 基于kashgari和BERT实现中文命名实体识别(NER)
查看>>
NLP 项目:维基百科文章爬虫和分类【01】 - 语料库阅读器
查看>>
NLP_什么是统计语言模型_条件概率的链式法则_n元统计语言模型_马尔科夫链_数据稀疏(出现了词库中没有的词)_统计语言模型的平滑策略---人工智能工作笔记0035
查看>>
NLP学习笔记:使用 Python 进行NLTK
查看>>
NLP问答系统:使用 Deepset SQUAD 和 SQuAD v2 度量评估
查看>>
NLP:使用 SciKit Learn 的文本矢量化方法
查看>>
Nmap扫描教程之Nmap基础知识
查看>>
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>