Lintcode55 Compare Strings solution 題解
【題目描述】
Compare two strings A and B, determine whether A contains all of the characters in B.The characters in string A and B are all Upper Case letters.
Notice:The characters of B in A are not necessary continuous or ordered.
比較兩個字符串A和B,確定A中是否包含B中所有的字符。字符串A和B中的字符都是 大寫字母
註意:在 A 中出現的 B 字符串裏的字符不需要連續或者有序。
【題目鏈接】
www.lintcode.com/en/problem/compare-strings/
【題目解析】
題目意思是問B中的所有字符是否都在A中,而不是單個字符。比如B="AABC"包含兩個「A」,而A="ABCD"只包含一個「A」,故返回false.
既然不是類似strstr那樣的匹配,直接使用兩重循環就不太合適了。題目中另外給的條件則是A和B都是全大小單詞,理解題意後容易想到的方案就是先遍歷A和B統計各字符出現的頻次,然後比較頻次大小即可。嗯,祭出萬能的哈希表。
【參考答案】
www.jiuzhang.com/solutions/compare-strings/
Lintcode55 Compare Strings solution 題解
相關推薦
Lintcode55 Compare Strings solution 題解
lintcode題解【題目描述】Compare two strings A and B, determine whether A contains all of the characters in B.The characters in string A and B are all Upper Case le
Lintcode28 Search a 2D Matrix solution 題解
efficient solution following matrix previous 【題目描述】Write an efficient algorithm that searches for a value in an m x n matrix.This matrix has the
Lintcode29 Interleaving String solution 題解
determine 參考答案 solution whether 字符串 【題目描述】Given three strings: s1, s2, s3, determine whether s3 is formed by the interleaving of s1 and s2.給出三個字符
Lintcode30 Insert Interval solution 題解
necessary solution start 記錄 元素 題目描述】Given a non-overlapping interval list which is sorted by start point.Insert a new interval into it, make sure
Lintcode31 Partition Array solution題解
lintcode題解【題目描述】Given an array nums of integers and an int k, partition the array (i.e move the elements in "nums") such that:All elements < k are moved
Lintcode32 Minimum Window Substring solution 題解
solution windows multiple contain minimum 【題目描述】Given a string source and a string target, find the minimum window in source which will contain a
Lintcode35 Reverse Linked List solution 題解
參考答案 linked solution 通用 【題目描述】Reverse a linked list.翻轉一個鏈表【題目鏈接】http://www.lintcode.com/en/problem/reverse-linked-list/【題目解析】這題要求我們翻轉[m, n]區間之間的鏈表。
Lintcode40 Implement Queue by Two Stacks solution 題解
lintcode【題目描述】As the title described, you should only use two stacks to implement a queue‘s actions.The queue should support push(element), pop() and top()
Lintcode70 Binary Tree Level Order Traversal II solution 題解
題解【題目描述】Given a binary tree, return the bottom-up level order traversal of its nodes‘ values. (ie, from left to right, level by level from leaf to root).給出
Lintcode185 Matrix Zigzag Traversal solution 題解
target row nts while 參考 columns lan ron clas 【題目描述】 Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in
Lintcode190 Next Permutation II solution 題解
implement pos cal mut 返回 all lex http number 【題目描述】 Implement next permutation, which rearranges numbers into the lexicographically next
Lintcode202 Segment Tree Query solution 題解
roo where segment blog 之一 attribute 描述 完成 con 【題目描述】 For an integer array (index from 0 to n-1, where n is the size of this array), in t
Lintcode203 Segment Tree Modify solution 題解
modify nis href roo 遞歸 target for xtra 解析 【題目描述】 For a Maximum Segment Tree, which each node has an extra value max to store the ma
Lintcode205 Interval Minimum Number solution 題解
簡書 calculate ray 描述 ger build calc dex nsh 【題目描述】 Given an integer array (index from 0 to n-1, where n is the size of this array),
Lintcode206 Interval Sum solution 題解
ref 以及 each segment suggest ron lint 給定一個整數數組 size 【題目描述】 Given an integer array (index from 0 to n-1, where n is the size of this
Lintcode207 Interval Sum II solution 題解
修改 sta sum 比較 ray 會有 .com suggest value 【題目描述】 Given an integer array in the construct method, implement two methods query(start, e
Lintcode363 Trapping Rain Water solution 題解
答案 計算 bar 題目 blog pin ons ini where 【題目描述】 Given n non-negative integers representing an elevation map where the width of each bar is 1
Lintcode364 Trapping Rain Water II solution 題解
DC 高度 開始 img 而且 jpeg 題解 c99 div 【題目描述】 Given n x m non-negative integers representing an elevation map 2d where the area of each ce
Lintcode362 Sliding Window Maximum solution 題解
lin ron cat 復雜度 zhang 範圍 ans tco 有意 【題目描述】 Given an array of n integer with duplicate number, and a moving window(size k), move the wind
Lintcode371 Print Numbers by Recursion solution 題解
http IT 應該 題解 sar 簡單 pretty 一個 BE 【題目描述】 Print numbers from 1 to the largest number with N digits by recursion. Notice It‘s pretty easy