随笔分类 -  java

摘要:Source Given an array of integers, the majority number is the number that occurs more than half of the size of the array. Find it. Example Given [1, 1 阅读全文
posted @ 2021-07-04 13:24 凌雨尘 阅读(89) 评论(0) 推荐(0)
摘要: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 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)
摘要: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)
摘要: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)
摘要:前言 了解IEEE-754之前,先了解下什么是十进制和二进制,以及它们之间如何转化 十进制 十进制按照字面意思来理解,就是逢十进一,比如我们现在用的货币也好,计算也好,都是十进制,用0-9十个数字来表示 二进制 十进制十逢十进一,二进制就是二进一,用0和1来表示所有的数字 二进制转十进制 二进制转十 阅读全文
posted @ 2020-07-05 12:32 凌雨尘 阅读(1322) 评论(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)
摘要: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-19 13:10 凌雨尘 阅读(112) 评论(0) 推荐(0)
摘要:Search in Rotated Sorted Array Problem Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this affect the run-time c 阅读全文
posted @ 2020-04-12 12:47 凌雨尘 阅读(162) 评论(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). You are given a t 阅读全文
posted @ 2020-04-05 22:06 凌雨尘 阅读(219) 评论(0) 推荐(0)
摘要:Problem A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ num[i+1], find a peak element and returni 阅读全文
posted @ 2020-03-08 12:22 凌雨尘 阅读(169) 评论(0) 推荐(0)