随笔分类 -  数据结构与算法

1
摘要:2017/3/14 15:14:02 概念 汉明距离(Hamming Distance)是使用在数据传输差错控制编码里面的,汉明距离是一个概念,它表示两个(相同长度)字对应位不同的数量,我们以d(x,y)表示两个字x,y之间的汉明距离。对两个字符串进行异或运算,并统计结果为1的个数,那么这个数就是汉 阅读全文
posted @ 2017-04-13 00:41 会飞的胖子 阅读(648) 评论(0) 推荐(1)
摘要:2017/3/13 12:59:41 看JDK源码,在HashMap类中发现了一个可以很好解决这个问题的方法。 问题描述: 假设给定 14,输出16;给定16,也输出16;给定17,输出32。输出满足给定数字的最小2的幂值 算法: 解析: 解析: 思路是填充1,比如 000110101,此时想要把高 阅读全文
posted @ 2017-04-13 00:41 会飞的胖子 阅读(247) 评论(0) 推荐(1)
摘要:本福特定律 测试结果 比例 1 : 30.0766922307 1 : 30.0766922307 1 : 30.0766922307 2 : 17.639213071 2 : 17.639213071 2 : 17.639213071 3 : 12.504168056 3 : 12.5041680 阅读全文
posted @ 2017-04-10 00:06 会飞的胖子 阅读(1881) 评论(0) 推荐(1)
摘要:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longes 阅读全文
posted @ 2017-04-01 16:13 会飞的胖子 阅读(212) 评论(0) 推荐(1)
摘要:2017/3/30 21:49:57 Determine whether an integer is a palindrome. Do this without extra space. 版本1:要求不能用额外空间说明不能建立数组存每个数字,只能依靠运算符。 1、需要额外考虑负数情况; 2、从两边开 阅读全文
posted @ 2017-03-30 22:05 会飞的胖子 阅读(182) 评论(0) 推荐(1)
摘要:2017/3/30 19:26:58 Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets 阅读全文
posted @ 2017-03-30 19:37 会飞的胖子 阅读(118) 评论(0) 推荐(1)
摘要:2017/3/30 14:28:32 Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example,Given n = 3, You should 阅读全文
posted @ 2017-03-30 15:28 会飞的胖子 阅读(110) 评论(0) 推荐(1)
摘要:2017/3/26 16:09:31 问题:求解稀疏矩阵乘法 版本1:朴素算法 θ(n3) 采用常规矩阵乘法公式 public static int[][] SparseMatrixMultiplication( int[][] A , int[][] B ){ int M = A.length; 阅读全文
posted @ 2017-03-30 14:32 会飞的胖子 阅读(174) 评论(0) 推荐(1)
摘要:2017/3/30 13:01:59 Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example,Given the foll 阅读全文
posted @ 2017-03-30 14:32 会飞的胖子 阅读(122) 评论(0) 推荐(0)
摘要:解法1:朴素算法 矩阵乘法公式 θ(n3) public static int[][] SparseMatrixMultiplication( int[][] A , int[][] B ){ int M = A.length; int N = B[0].length;//取列长 int K = A 阅读全文
posted @ 2017-03-27 22:04 会飞的胖子 阅读(249) 评论(0) 推荐(0)
摘要:2017/3/23 17:52:07 Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the arr 阅读全文
posted @ 2017-03-27 00:00 会飞的胖子 阅读(229) 评论(0) 推荐(0)
摘要:2017/3/23 15:41:47 Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. N 阅读全文
posted @ 2017-03-26 23:59 会飞的胖子 阅读(158) 评论(0) 推荐(0)
摘要:2017/3/23 22:23:57 Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Given num = 16, return true. Given 阅读全文
posted @ 2017-03-26 23:59 会飞的胖子 阅读(151) 评论(0) 推荐(0)
摘要:2017/3/16 22:36:02 Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, t 阅读全文
posted @ 2017-03-26 23:58 会飞的胖子 阅读(162) 评论(0) 推荐(0)
摘要:2017/3/14 15:23:55 The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integ 阅读全文
posted @ 2017-03-26 23:58 会飞的胖子 阅读(173) 评论(0) 推荐(0)
摘要:2017/3/14 15:36:44 Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation. N 阅读全文
posted @ 2017-03-26 23:57 会飞的胖子 阅读(148) 评论(0) 推荐(0)
摘要:2017/3/15 21:47:04 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a 阅读全文
posted @ 2017-03-26 23:57 会飞的胖子 阅读(175) 评论(0) 推荐(0)
摘要:2017/3/16 20:03:07 Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example:Given a = 1 and b = 2, retu 阅读全文
posted @ 2017-03-26 23:57 会飞的胖子 阅读(164) 评论(0) 推荐(0)
摘要:Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have ex 阅读全文
posted @ 2017-03-26 23:56 会飞的胖子 阅读(335) 评论(0) 推荐(0)
摘要:2017/3/24 22:38:54 《算法导论》第四章 分治策略 练习4.1-3 要求比较三种方法的时间走势,找出递归算法和暴力算法的分界点(前期暴力算法会更快)。 该问题有三个常规解法:暴力、分治法、动态规划 实践代码: # -*- coding: utf-8 -*- from time imp 阅读全文
posted @ 2017-03-25 23:40 会飞的胖子 阅读(168) 评论(0) 推荐(0)

1