class Solution: def reverseWords(self, s: str) -> str: return " ".join(s.strip().split()[::-1]) # return " ".join([t for t in s.strip().split()][::-1])
不断向右移动 right 指针,每次移动到非零数,则将左右指针对应的数交换,交换同时将 left 右移。
此时,left 指针左边均为处理好的非零数,而从 left 指针指向的位置开始, right 指针左边都为 0。
遍历结束之后,则所有 0 都移动到了右侧,且保持了非零数的相对位置。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
class Solution: def moveZeroes(self, nums): left = 0 right = 0 while right < len(nums): # 不断向右移动 right 指针 if nums[right] != 0: # 每次移动到非零数,则将左右指针对应的数交换, nums[left], nums[right] = nums[right], nums[left] # 交换同时将 left 右移 left += 1 # 不断向右移动 right 指针 right += 1 print(nums) if __name__ == "__main__": st = Solution().moveZeroes([1,1,0,1,0,1])
class Solution: def pivotIndex1(self, nums): left = 0 right = 0 for index in range(len(nums)): # 先将数组全部的数和求出,作为右边的数 right += nums[index] right = sum(nums) for move in range(len(nums)): # 右边做减法 right -= nums[move] print("--right:%s--index-%s-" % (right,move)) # 当左边和右边的值相等,返回当前索引 if left == right: return move # 左边做加法 left += nums[move] print("--left:%s--index-%s-" % (left,move)) return -1
if __name__ == "__main__":
data = [1,3,7,8,6,5] t = Solution().pivotIndex1(data) print(t)
dz> list app.activity.forintent Find activities that can handle the given intent app.activity.info Gets information about exported activities. app.activity.start Start an Activity app.broadcast.info Get information about broadcast receivers app.broadcast.send Send broadcast using an intent app.broadcast.sniff Register a broadcast receiver that can sniff particular intents app.package.attacksurface Get attack surface of package app.package.backup Lists packages that use the backup API (returns true on FLAG_ALLOW_BACKUP) app.package.debuggable Find debuggable packages .....
dz> run app.broadcast.info -a org.owasp.goatdroid.fourgoats Package: org.owasp.goatdroid.fourgoats org.owasp.goatdroid.fourgoats.broadcastreceivers.SendSMSNowReceiver Permission: null
查看反编译出(apktool d goatdroid.apk)的AndroidManifest.xml文件,可看到将receiver的exported设置未进行设置(由于存在了filter,默认属性为true)。说明存在越权问题,可发送恶意广播,伪造消息等等。
当前broadcast Receiver 是否可以从当前应用外部获取Receiver message true,可以;false 不可以。如果为false ,当前broadcast Receiver 只能收到同一个应用或者拥有同一 user ID 应用发出广播。
run app.package.attacksurface org.owasp.goatdroid.fourgoats
信息泄露利用
扫描并获取Content Provider信息,并列出了可访问内容URI的列表和路径:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
dz> run scanner.provider.finduris -a com.mwr.example.sieve Scanning com.mwr.example.sieve... Unable to Query content://com.mwr.example.sieve.DBContentProvider/ Unable to Query content://com.mwr.example.sieve.FileBackupProvider/ Unable to Query content://com.mwr.example.sieve.DBContentProvider Able to Query content://com.mwr.example.sieve.DBContentProvider/Passwords/ Able to Query content://com.mwr.example.sieve.DBContentProvider/Keys/ Unable to Query content://com.mwr.example.sieve.FileBackupProvider Able to Query content://com.mwr.example.sieve.DBContentProvider/Passwords Unable to Query content://com.mwr.example.sieve.DBContentProvider/Keys