codewars遇到的比较有意思的题目】的更多相关文章

题目要求是编写一个函数用来检测一个字符串,字符串是一系列单词组成,每个单词间用空格隔开,不用考虑空字符串的情况,返回长度最小的那个单词的长度. 博主刚入门PHP,技术还很菜,没有想出来,看了其他人的解决方案,最简洁的方案是 function findShort($str){ return min(array_map('strlen', (explode(' ', $str)))); } explode()是把字符串打散成索引数组,意思是每个单词都成了数组的一个键值,array_map()是指将用…
# 数据结构类 ### 线段树 segment tree http://www.careercup.com/question?id=5165570324430848 找区间内的value的个数 二维线段树 http://www.careercup.com/question?id=5746897784406016 http://www.careercup.com/question?id=15443800 关于线段树的构造,参考<手写代码必备手册>(https://github.com/soulm…
public class Base { private String baseName = "base"; public Base() { callName(); } public void callName() { System.out.println(baseName); } static class Sub extends Base { private String baseName = "sub"; public void callName(){ Syste…
题意: 一颗二叉树可以看成一个杠杆,左右俩边有重量,有到支点长度,判断整个树是否平衡(根据杠杆原理),如果当前结点有左孩子,那么当前左边的重量就是左孩子的总和,右边同理 递归,发现scanf和cin的效率差好多. AC时间:20ms(scanf),80ms(cin) #include<stdio.h> #include<iostream> #include<queue> #include<memory.h> using namespace std; cons…
231. 2的幂 2^3=8 得  8是2的幂 判断一个整数是不是2的幂,可根据二进制来分析.2的幂如2,4,8,等有一个特点: 二进制数首位为1,其他位为0,如2为10,4为100 2&(2-1)=0   4&(4-1)=0     即得出结论如果一个数n为2的幂,则n(n-1)=0 258 各位相加的过程为:3 + 8 = 11, 1 + 1 = 2. 由于 2 是一位数,所以返回 2. 有如下关系:num = a * 10000 + b * 1000 + c * 100 + d *…
偶然机会,在codewars上面开始做题,遇到一道有意思的题目,记录一下: 题目是这样的: In this kata, you will write a function that returns the positions and the values of the "peaks" (or local maxima) of a numeric array. For example, the array arr = [0, 1, 2, 5, 1, 0] has a peak at po…
楼主比较喜欢看一些很短但很有意思的题目,无意间又瞥到了一题,大家不妨可以一试.(原题链接猛戳这里) function Fn1() { this.name = 'peter'; return { name: 'jack' }; } function Fn2() { this.name = 'peter'; return 'jack'; } var obj1 = new Fn1(); var obj2 = new Fn2(); console.log(obj1.name, obj2.name); 或…
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201…
1.数列(seq2.pas/c/cpp) 题目描述 一个数列定义如下:f(1) = 1,f(2) = 1,f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.给定 A,B 和 n 的值,要求计算 f(n)的值. 输入格式 仅一行包含 3 个整数 A,B 和 n,其中(1≤ A, B ≤1000, 1 ≤n≤100,000,000). 输出格式 仅一行,一个整数,即 f(n)的值. 输入输出样例 input: | output:------------------…
转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093.1094.1095.1096.1097.1098.1106.1108.1157…