小编Gil*_*Lee的帖子

Android setOnItemClickListener 与 setOnClickListener

据我所知,有两种方法可以处理不同列表项上的点击:

  1. 使用setTag()到集类型在适配器列表中的项目,然后setOnItemClickListener()在列表getTag()视图的区分类型,如下所示:

listview.setOnItemClickListener(new OnItemClcikListener(){});

  1. 在适配器内部,setOnClickListener()在 期间单独为每个项目getView(),像这样:

item.setOnClickListener(new OnClickListener() {});

有什么区别,哪个更受欢迎?

android listview onitemclicklistener onclicklistener

5
推荐指数
1
解决办法
2206
查看次数

自制没有这样的桶

当我试图解决一个问题时

brew uninstall gcc
Run Code Online (Sandbox Code Playgroud)

我收到错误

No such keg: /usr/local/Cellar/gcc
Run Code Online (Sandbox Code Playgroud)

但实际上我已经安装了 gcc

which gcc
/usr/bin/gcc
Run Code Online (Sandbox Code Playgroud)

看起来brew 指向的是空的地方。即我也安装了 python/usr/bin/brew info python显示了Not installed.

我该如何解决这个问题以将所有这些工具链接到brew?谢谢

python macos homebrew

5
推荐指数
1
解决办法
3万
查看次数

Python中的Palindrome链表具有O(1)额外空间

这是#234 Leetcode问题:

给定一个单链表,确定它是否是回文。

跟进:您能在O(n)时间和O(1)空间中做到吗?

O(n)空间很容易解决这个问题。但是,我不知道O(1)解决方案。我想到的唯一方法是使用递归:

# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    current = None

    def isPalindrome(self, head):
        """
        :type head: ListNode
        :rtype: bool
        """
        if not head or not head.next:
            return True

        self.current = head

        return self.compare(head)

    def compare(self, head):
        if not head: return True

        if not self.compare(head.next): return False

        if head.val != self.current.val:
            return False
        else:
            self.current = self.current.next
            return True
Run Code Online (Sandbox Code Playgroud)

这适用于小样本,但给出

超过最大递归深度 …

python algorithm linked-list palindrome

1
推荐指数
1
解决办法
1668
查看次数