11.8 Imagine you are reading in a stream of integers. Periodically, you wish to be able to look up the rank of a number x (the number of values less than or equal tox). Implement the data structures and algorithms to support these operations.That is,…
18.1 Write a function that adds two numbers. You should not use + or any arithmetic operators. 这道题让我们实现两数相加,但是不能用加号或者其他什么数学运算符号,那么我们只能回归计算机运算的本质,位操作Bit Manipulation,我们在做加法运算的时候,每位相加之后可能会有进位Carry产生,然后在下一位计算时需要加上进位一起运算,那么我们能不能将两部分拆开呢,我们来看一个例子759+674 1.…
Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18543 Accepted Submission(s): 11246 Problem Description The inversion number of a given number sequence a1, a2, ..., a…
11.3 Given a sorted array of n integers that has been rotated an unknown number of times, write code to find an element in the array. You may assume that the array was originally sorted in increasing order. EXAMPLE Input: find 5 in {15, 16, 19, 20, 2…
11.7 A circus is designing a tower routine consisting of people standing atop one another's shoulders. For practical and aesthetic reasons, each person must be both shorter and lighter than the person below him or her. Given the heights and weights o…
11.1 You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted orde. LeetCode上的原题,请参见我之前的博客Merge Sorted Array 混合插入有序数组. class Solution { public: void merge(vector<int>…
11.2 Write a method to sort an array of strings so that all the anagrams are next to each other. 这道题让我们给一个字符串数组排序,让所有的变位词Anagrams排在一起,关于变位词,LeetCode里有两道相关的题目Anagrams 错位词和Valid Anagram 验证变位词.那么对于这道题,我们有两种方法可以实现,先来看第一种方法,来重写sort中的比较函数compare,参见代码如下: 解法…
11.4 Imagine you have a 20 GB file with one string per line. Explain how you would sort the file. 这道题说给了我们一个20GB大小的文件,每行有一个字符串,让我们给文件内容排序.那么既然强调了这么大的一个文件,肯定不想让我们直接进入内存中,那么我们可以把大文件分块,每块xMB,其中x的大小为我们可用的内存大小,我们对每块分别排序,然后把所有的有序块进行合并,这样我们就能得到一个有序的文件了.…
11.5 Given a sorted array of strings which is interspersed with empty strings, write a method to find the location of a given string. EXAMPLE Input: find "ball" in {"at", "", "", "", "ball", &quo…
11.6 Given an M x N matrix in which each row and each column is sorted in ascending order, write a method to find an element. LeetCode上的原题,请参见我之前的博客Search a 2D Matrix 搜索一个二维矩阵和Search a 2D Matrix II 搜索一个二维矩阵之二. class Solution { public: bool findElemen…
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16742 Accepted Submission(s): 7280 Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble numb…
A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying two smaller natural numbers. Now lets define a number NN as the supreme number if and only if each number made up of an non-empty subsequence of all…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcode-cn.com/problems/confusing-number/ 题目描述 Given a number N, return true if and only if it is a confusing number, which satisfies the following condition…
A number system with moduli is defined by a vector of k moduli, [m1,m2, ···,mk]. The moduli must be pairwise co-prime, which means that, for any pair of moduli, the only common factor is 1. In such a system each number n is represented by a string "-x…