今天继续刷题,但感觉今天遇到的每个题都有点困惑,大家一起帮忙看看:
1、旋转字符串

我的代码:
"""
@param str: An array of char
@param offset: An integer
@return: nothing
"""
def rotateString(self, str, offset):
length = len(str);
if offset == 0 or offset>=length:
return str
else:
str1 = str[0:length-offset]
str2 = str[length-offset:length]
return str2+str1
代码也经过多次验证,但是就是提交不通过,报以下错误信息:

好吧,有知道的朋友吗,解下惑哈~
2、合并排序数组 II

我的代码:
"""
@param A: sorted integer array A
@param B: sorted integer array B
@return: A new sorted integer array
"""
def mergeSortedArray(self, A, B):
A.sort()
B.sort()
C = A+B
C.sort()
return C
答案正确
3、Fizz Buzz 问题

代码:
"""
@param n: An integer
@return: A list of strings.
"""
def fizzBuzz(self, n):
_str = []
_index = 1
while _index<=n:
if _index%3==0 and _index%5!=0:
_str.append("fizz")
elif _index%5==0 and _index%3!=0:
_str.append("buzz")
elif _index%5==0 and _index%3==0:
_str.append("fizz buzz")
else:
_str.append(str(_index))
_index+=1
return _str
今天就只做这三道题吧,后期难度将会循序渐进,兄dai,你get到了吗?
网友评论