摘要:
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S="ADOBECODEBANC"T="ABC"Minimum window is"BANC".Note:If there is no such window in S that covers all characters in T, return the emtpy 阅读全文
摘要:
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.维护一个新的链表,用两个指针指向两个链表,类似merge sot的比较。 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * L... 阅读全文
摘要:
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and B aremandnrespectively.考虑从后往前比较,这样就不会产生需要数据后移的问题了。时间复杂度O(n+m) 1 class Solution { 2 public: 3 voi... 阅读全文
摘要:
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.For example,Givenboard=[ [&q 阅读全文
摘要:
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keysless thanthe node's key.The right subtree of a node contains only nodes with keysgreater thanthe node's key.Both the left and ri 阅读全文