Two-dimensional array of find, replace spaces

Two-dimensional array lookup

(The length of each one-dimensional array of same), each row from left to right in order of ascending sort, to sort each column in a two-dimensional array in order of increasing from top to bottom. A complete function, enter such a two-dimensional array and an integer, it is determined whether the array contains the integer.

class Solution:
    # array 二维列表
    def Find(self, target, array):
        if not array:
            return False
        i,j=0, len(array[0])-1
        while i<len(array) and j >=0:
            if array[i][j]>target:
                j-=1
            elif array[i][j]<target:
                i+=1
            else:
                return True
        return False

Replace spaces

Please implement a function, a string to replace each space to "20%." For example, when the string is We Are Happy. After the string is replaced after We% 20Are% 20Happy.

# -*- coding:utf-8 -*-
class Solution:
    # s 源字符串
    def replaceSpace(self, s):
        #不用考虑空
        a = s.split(' ')
        return ('%20'.join(a))

Guess you like

Origin www.cnblogs.com/qizhien/p/11607268.html