Leetcode Array 知识点总结

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tinkle181129/article/details/80333687
class Solution(object):
    def flipAndInvertImage(self, A):
        """
        :type A: List[List[int]]
        :rtype: List[List[int]]
        """
        rows = len(A)
        if rows == 0: return A
        cols = len(A[0])
        for i in range(rows):
            start = 0
            end = cols-1
            while(start<end):
                A[i][start],A[i][end] = A[i][end]^1,A[i][start]^1
                start+=1
                end-=1
            if start == end:
                A[i][start] = A[i][start] ^ 1
        return A
class Solution(object):
    def numberOfLines(self, widths, S):
        """
        :type widths: List[int]
        :type S: str
        :rtype: List[int]
        """
        line,units = 1,0
        for s in S:
            tmp = widths[ord(s)-ord('a')]
            if units+tmp>100:
                line+=1
                units=0
            units+=tmp
        return [line,units]
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页