/images/avatar.png

lc680. Valid Palindrome II

Given a string s, return true if the s can be palindrome after deleting at most one character from it.

Example 1:

1
2
Input: s = "aba"
Output: true

Example 2:

1
2
3
Input: s = "abca"
Output: true
Explanation: You could delete the character 'c'.

Example 3:

1
2
Input: s = "abc"
Output: false

Constraints:

  • 1 <= s.length <= 105
  • s consists of lowercase English letters.
解题思路:

如果最多删除一个字母可以使字符串满足回文序列即返回true。

lc953. Verifying an Alien Dictionary

In an alien language, surprisingly, they also use English lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters.

Given a sequence of words written in the alien language, and the order of the alphabet, return true if and only if the given words are sorted lexicographically in this alien language.

Example 1:

1
2
3
Input: words = ["hello","leetcode"], order = "hlabcdefgijkmnopqrstuvwxyz"
Output: true
Explanation: As 'h' comes before 'l' in this language, then the sequence is sorted.

Example 2:

lc1249. Minimum Remove to Make Valid Parentheses

Given a string s of '(' , ')' and lowercase English characters.

Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string.

Formally, a parentheses string is valid if and only if:

  • It is the empty string, contains only lowercase characters, or
  • It can be written as AB (A concatenated with B), where A and B are valid strings, or
  • It can be written as (A), where A is a valid string.

Example 1:

lc155.Min Stack

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

Implement the MinStack class:

  • MinStack() initializes the stack object.
  • void push(int val) pushes the element val onto the stack.
  • void pop() removes the element on the top of the stack.
  • int top() gets the top element of the stack.
  • int getMin() retrieves the minimum element in the stack.
Example 1:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
Input
["MinStack","push","push","push","getMin","pop","top","getMin"]
[[],[-2],[0],[-3],[],[],[],[]]

Output
[null,null,null,null,-3,null,0,-2]

Explanation
MinStack minStack = new MinStack();
minStack.push(-2);
minStack.push(0);
minStack.push(-3);
minStack.getMin(); // return -3
minStack.pop();
minStack.top();    // return 0
minStack.getMin(); // return -2 
Constraints:
  • -231 <= val <= 231 - 1
  • Methods pop, top and getMinoperations will always be called on non-empty stacks.
  • At most 3 * 104 calls will be made to push, pop, top, and getMin.
解题思路

Stack进行push和pop操作都非常简单,困难的是如何操作getMin。

剑指 Offer 09. 用两个栈实现队列

用两个栈实现一个队列。队列的声明如下,请实现它的两个函数 appendTail 和 deleteHead ,分别完成在队列尾部插入整数和在队列头部删除整数的功能。(若队列中没有元素,deleteHead 操作返回 -1 )

示例 1:

输入:

1
2
3
["CQueue","appendTail","deleteHead","deleteHead"]
[[],[3],[],[]]
输出:[null,null,3,-1]

示例 2:

输入:

1
2
3
["CQueue","deleteHead","appendTail","appendTail","deleteHead","deleteHead"]
[[],[],[5],[2],[],[]]
输出:[null,-1,null,null,5,2]

提示:

1
2
1 <= values <= 10000
最多会对 appendTail、deleteHead 进行 10000 次调用

来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

解题思路

输入为两个栈,

第一个栈对应的是操作: [“CQueue”,“appendTail”,“deleteHead”,“deleteHead”]

CQueue表示init一个CQueue object

appendTail表示调用appendTail函数

deleteHead表示调用deleteHead函数

第二个栈对应的是操作的值。

栈(Stack)的特点是先入后出,但是我们需要实现直接操作Head的功能。因此使用两个Stack可以实现列表倒序。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
class CQueue:
    def __init__(self):
        self.A, self.B = [], []

    def appendTail(self, value: int) -> None:
        self.A.append(value)

    def deleteHead(self) -> int:
        if self.B: return self.B.pop()
        if not self.A: return -1
        while self.A:
            self.B.append(self.A.pop())
        return self.B.pop()

时间复杂度: appendTail()为O(1), deleteHead()为O(N)

[NMI] A geometric deep learning approach to predict binding conformations of bioactive molecules 解读

Title: A geometric deep learning approach to predict binding conformations of bioactive molecules

DOI: https://doi.org/10.1038/s42256-021-00409-9

INFO: NATURE MACHINE INTELLIGENCE | VOL 3 | DECEMBER 2021

发表周期: Received: 18 May 2021; Accepted: 28 September 2021; Published online: 2 December 2021

药物设计是近年来AI应用的极火领域之一,其中一个最有挑战的问题就是空间结构设计。

One of the difficulties arises from the fact that only a small portion of the large chemical space will bind to a specific biological target and result in a therapeutic effect.