摘要: Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.乘法原理,感觉如果用数组来计算会简单很多,用字符串必须再每次循环后处理一下高位的进位问题,比较麻烦。 1 class Solution { 2 public: 3 string multiply(string num1, string num2) { 4 // St... 阅读全文
posted @ 2012-11-16 22:49 chkkch 阅读(1190) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2012-11-16 22:02 chkkch 阅读(5745) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2012-11-16 11:47 chkkch 阅读(4971) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2012-11-16 11:34 chkkch 阅读(5533) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2012-11-16 10:57 chkkch 阅读(2012) 评论(1) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2012-11-16 09:23 chkkch 阅读(4486) 评论(2) 推荐(0) 编辑