随笔分类 -  algorithms

摘要:Source Print numbers from 1 to the largest number with N digits by recursion. Example Given N = 1, return [1,2,3,4,5,6,7,8,9]. Given N = 2, return [1, 阅读全文
posted @ 2021-06-20 14:21 凌雨尘 阅读(56) 评论(0) 推荐(0)
摘要:Source Write a function that add two numbers A and B. You should not use + or any arithmetic operators. Example Given a=1 and b=2 return 3 Note There 阅读全文
posted @ 2021-06-06 16:14 凌雨尘 阅读(130) 评论(0) 推荐(0)
摘要:Source Find the Nth number in Fibonacci sequence. A Fibonacci sequence is defined as follow: The first two numbers are 0 and 1. The i th number is the 阅读全文
posted @ 2021-05-09 12:09 凌雨尘 阅读(190) 评论(0) 推荐(0)
摘要:Source Count how many 1 in binary representation of a 32-bit integer. Example Given 32, return 1 Given 5, return 2 Given 1023, return 9 Challenge If t 阅读全文
posted @ 2021-04-11 12:10 凌雨尘 阅读(69) 评论(0) 推荐(0)
摘要:Source In data structure Hash, hash function is used to convert a string(or any other type) into an integer smaller than hash size and bigger or equal 阅读全文
posted @ 2021-04-05 20:37 凌雨尘 阅读(188) 评论(0) 推荐(0)
摘要:Source 计算 a^n % b,其中a,b和n都是32位的非负整数 题解 数学题,考察整数求模的一些特性,不知道这个特性的话此题一时半会解不出来,本题中利用的关键特性为: (a * b) % p = ((a % p) * (b % p)) % p 即 a 与 b 的乘积模 p 的值等于 a, b 阅读全文
posted @ 2021-03-28 12:50 凌雨尘 阅读(95) 评论(0) 推荐(0)
摘要:Source Given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits between i and j in N equal to M (e g , M beco 阅读全文
posted @ 2021-03-07 13:05 凌雨尘 阅读(115) 评论(0) 推荐(0)
摘要:Source Given n, how many structurally unique BSTs (binary search trees) that store values 1...n? Example Given n = 3, there are a total of 5 unique BS 阅读全文
posted @ 2021-02-28 14:23 凌雨尘 阅读(93) 评论(0) 推荐(0)
摘要:Source Write an algorithm which computes the number of trailing zeros in n factorial. Example 11! = 39916800, so the out should be 2 Challenge O(log N 阅读全文
posted @ 2021-02-17 13:58 凌雨尘 阅读(125) 评论(0) 推荐(0)
摘要:Source Determine the number of bits required to convert integer A to integer B Example Given n = 31, m = 14,return 2 (31)10=(11111)2 (14)10=(01110)2 题 阅读全文
posted @ 2021-01-31 13:10 凌雨尘 阅读(114) 评论(0) 推荐(0)
摘要:Source Using O(1) time to check whether an integer n is a power of 2. Example For n=4, return true; For n=5, return false; Challenge O(1) time 题解 咋看起来 阅读全文
posted @ 2021-01-10 16:08 凌雨尘 阅读(103) 评论(0) 推荐(0)
摘要:Source Given 2*n + 2 numbers, every numbers occurs twice except two, find them. Example Given [1,2,2,3,4,4,5,3] return 1 and 5 Challenge O(n) time, O( 阅读全文
posted @ 2020-11-08 13:33 凌雨尘 阅读(105) 评论(0) 推荐(0)
摘要:Source Given 3*n + 1 numbers, every numbers occurs triple times except one, find it. Example Given [1,1,2,3,3,3,2,2,4,1] return 4 Challenge One-pass, 阅读全文
posted @ 2020-10-25 12:39 凌雨尘 阅读(127) 评论(0) 推荐(0)
摘要:Problem 「找单数」系列题,技巧性较强,需要灵活运用位运算的特性。 Given 2*n + 1 numbers, every numbers occurs twice except one, find it. Example Given [1,2,2,1,3,4,3], return 4 Ch 阅读全文
posted @ 2020-10-11 12:27 凌雨尘 阅读(151) 评论(0) 推荐(0)
摘要:Problem Given n pieces of wood with length L[i] (integer array). Cut them into smallpieces to guarantee you could have equal or more than k pieces wit 阅读全文
posted @ 2020-09-20 12:27 凌雨尘 阅读(301) 评论(0) 推荐(0)
摘要:实现 int sqrt(int x) 函数 计算并返回 x 的平方根,其中 x 是非负整数。 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去。 示例 1: 输入: 4 输出: 2 示例 2: 输入: 8 输出: 2 说明: 8 的平方根是 2.82842..., 由于返回类型是整数,小数 阅读全文
posted @ 2020-09-06 12:38 凌雨尘 阅读(374) 评论(0) 推荐(0)
摘要:Problem There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. Example Given A=[1,2,3,4,5,6] and  阅读全文
posted @ 2020-08-16 12:33 凌雨尘 阅读(180) 评论(0) 推荐(0)
摘要:一、背景 基本上每一个需要对接支付公司的项目都有这样一个烦恼:不同的支付公司给到你的支付费率是不一样的,微信支付宝收的费率是0.6%(不知道后面有没有降低),A支付公司费率的是0.5%,B支付公司费率是0.48%。。。此外还有活动等 大部分公司一开始只对接一家或两家支付公司,后面的可能会由于一些原因 阅读全文
posted @ 2020-06-06 17:30 凌雨尘 阅读(7223) 评论(0) 推荐(1)
摘要:要求: 有一个key=>value格式的数据,现在需要格式化将其输出,以key=value的形式输出,两个key=value直接用分号;隔开,如果value是数组的话,输出格式是这样的:key.item=value 例子: { "person":{ "name":"pig", "age":"18", 阅读全文
posted @ 2020-05-10 11:45 凌雨尘 阅读(718) 评论(0) 推荐(0)
摘要:Problem Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum 阅读全文
posted @ 2020-04-26 12:14 凌雨尘 阅读(108) 评论(0) 推荐(0)