注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
第一题:
You are given an integer X. You must choose two adjacent digits and replace them with the larger of these two digits. For example, from the integer X = 233614, you can obtain:
33614 (by replacing 23 with 3);
23614 (by replacing 33 with 3 or 36 with 6);
23364 (by replacing 61 with 6 or 14 with 4); You want to find the smallest number that can be obtained from X by replacing two adjacent digits with the larger of the two. In the above example, the smallest such number is 23364. Write a function: class Solution {public int solution (int X);}that, given a positive integer X, returns the smallest number that can be obtained from X by replacing two adjacent digits with the larger of the two. For example, given X = 233614, the function should return 23364, as explained above. Assume that: X islign="left">that, given a string S consisting of N characters which contains the listing of a file system, returns the total of lengths (in
characters) modulo 1,000,000,007 of the absolute paths to all the directories directly containing at least one image file. For
example, given the sample listing shown above, the function should return 16, as explained above. If there are no image
files in the listing, the function should return 0.
Assume that:
N is an integer within the range [1..3,000,000];
string S consists only of alphanumerical characters (a-z and/or A-Z and/or 0-9), spaces, dots (.) and end-
of-line characters;
string S is a correct listing of a file system contents.Complexity:
expected worst-case time complexity is 0(N);
expected worst-case space complexity is 0(N) (not counting the storage required for input arguments).
|