HackerRank
文章平均质量分 75
小李34234324
爱好Data Structures, Algorithms, Python/C++/Java/JavaScript/Scala/Golang, Machine Learning, AI, 大数据等
展开
-
最大子数组和(The Maximum Subarray)
问题:求一个整型数组的(1)最大连续子数组和以及(2)不要求连续的最大子数组和要求 返回的结果不能使空数组。解答思路:(1)从前往后扫描数组,当前边累加的和大于零的时候,说明这个序列对结果有益,则保留,并且加上当前数组元素A[i]。如果当前累加的和小于等于0,说明已经扫描序列会降低结果的值,有害,则抛弃,当前最大结果则为当前元素A[i]。该算法的时间复杂度是O(n).原创 2016-05-15 14:43:00 · 520 阅读 · 0 评论 -
对角线差(Diagonal Difference)
题目:给出一个N*N的二维整数数组,计算主对角线元素和和副对角线和之间的差。Sample Input311 2 44 5 610 8 -12Sample Output15我的解答:import java.io.*;import java.uti原创 2016-05-15 16:04:22 · 2094 阅读 · 0 评论 -
打印一个楼梯(Staircase)
打印一个高度为N由#符号填充的楼梯比如N=6时打印 # ## ### #### ###########我的解答:import java.io.*;import java.util.*;public class Staircase { public static void main(String[] args) {原创 2016-05-15 16:44:08 · 1022 阅读 · 0 评论 -
判断字符串是不是回文,使用C++、Python两种语言
//题目, 判断一个字符串是不是“回文” #include <iostream>using namespace std; //! corebool is_palindrome(char * s){ int end = strlen(s) - 1; int pre = 0; while(pre < end){ if(s[pre...原创 2018-12-21 10:58:40 · 538 阅读 · 0 评论 -
Python算法笔试题目,破解Hash值,回溯法
Find the string which has this hash: 25267566250558The string has length8.Characters can befrom: c,e,i,a,r,w,u,s,pThe hash functionworks like this:hash(str): 1.LETTERS = c, e, i, a, r, w,...原创 2018-12-21 11:00:27 · 106 阅读 · 0 评论 -
Python笔试题目:求最大的K个数子,解法一,最快速实现的方法
题目:Givena array of 10,000 random intergers, select the biggest 100 numbers.1)The order of the result numbers does not matter;2)Take care about the algorithm performance and big O complexity.上...原创 2018-12-21 11:02:51 · 315 阅读 · 0 评论 -
Python笔试题目:求最大的K个数子,解法二,适合小型数据集的情况
题目:Givena array of 10,000 random intergers, select the biggest 100 numbers.1)The order of the result numbers does not matter;2)Take care about the algorithm performance and big O complexity.我...原创 2018-12-21 11:03:37 · 191 阅读 · 0 评论