leetcode477
题目要求
1 | The Hamming distance between two integers is the number of positions at which the corresponding bits are different. |
计算N个数字之间的汉明码距离之和。
汉明码是指两个数字的二进制表示形式中,在对应位置上值不同的数量总和。如2和4,4的二进制表达式为100, 2的二进制表达式010,则二者在第二位和第三位的值不同,因此汉明码值为2。
1 | The Hamming distance between two integers is the number of positions at which the corresponding bits are different. |
计算N个数字之间的汉明码距离之和。
汉明码是指两个数字的二进制表示形式中,在对应位置上值不同的数量总和。如2和4,4的二进制表达式为100, 2的二进制表达式010,则二者在第二位和第三位的值不同,因此汉明码值为2。
1 | Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....". |
假设存在一个从a-z26个字母无限循环的字符串s,现在输入一个字符串p,问该字符串有多少个子字符串在s中循环出现?
1 | In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue. |
已知有m个0和n个1,问最多能构成数组中多少个数字。已知每个0和1只能使用一次。
1 | Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping. |
使用二维数组表示区间组,每一个子数组的第一个值表示区间的开始坐标,第二个值表示区间的结束坐标。计算最少进行多少次删除操作,可以确保剩下的区间不会产生任何重叠。
1 | You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. |
用一个二维数组来表示一块岛屿的土地情况,其中1代表土地,0代表海洋。要求计算出岛屿的周长。题目中特别强调了不存在内陆湖的存在,其实是变相的降低了题目的难度。即我们只要看到1和0相邻,就可以判断出到了岛的边缘。
1 | A gene string can be represented by an 8-character long string, with choices from "A", "C", "G", "T". |
假设现在有两个基因序列,并且用一个字符串数组bank来表示一个基因序列银行。已知每一步可以将当前基因序列中的一位进行改变,变成另一个已知的基因序列。问最少需要多少步可以将初始的基因序列转化为目标基因序列。如果无法转换,则返回-1。
1 | Given a non-empty integer array, find the minimum number of moves required to make all array elements equal, where a move is incrementing a selected element by 1 or decrementing a selected element by 1. |
问最少需要多少次操作,能够将数组中所有元素的值修改为一样的(操作是指将数组中的元素加一或者减一)
1 | Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 10000. |
判断一个非空的字符串是否是一个子字符串拼接多次构成的。
1 | Given a string, sort it in decreasing order based on the frequency of characters. |
将字符串按照每个字母出现的次数,按照出现次数越多的字母组成的子字符串越靠前,生成一个新的字符串。这里要注意大小写敏感。