题目描述:
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.
For example, given the array [2,3 ...
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.
For example, given the array [2,3 ...
Implement a trie with insert, search, and startsWith methods.
Note:
You may assume that all inputs are consist of lowercase letters a-z.
实现字典树,包含插入,查找和前缀查找方法。
注意:
你可以假设所有的输入只包含小写字母a-z
本题考查字典树数据结构的基础知识。
Trie使用孩子表示法存储,TrieNode为字典树的节点,包含属性childs和isWord。
其中childs为dict,存储当前节点的后代节点;isWord为布尔值,表示当前节点是否存储了一个单词。
class ...
There are a total of n courses you have to take, labeled from 0 to n - 1.
Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as ...
Reverse a singly linked list.
Hint:
A linked list can be reversed either iteratively or recursively. Could you implement both?
单链表逆置
提示:
用递归和迭代方式分别实现。
链表基本操作,递归方式参考:https://leetcode.com/discuss/34474/in-place-iterative-and-recursive-java-solution
迭代版本:
# Definition for singly-linked list ...
Given two strings s and t, determine if they are isomorphic.
Two strings are isomorphic if the characters in s can be replaced to get t.
All occurrences of a character must be replaced with another character while preserving ...