To the Top
File:  root - text - article - 2019 - 11 - buddy-strings.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 691 Views, 14575 Search Bots | 109 Words

Subscribe to Feed Burner | Browse | Archive
Hi, here's your problem today. This problem was recently asked by AirBNB:

Given two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B.

Example 1:
Input: A = "ab", B = "ba"
Output: true
Example 2:

Input: A = "ab", B = "ab"
Output: false
Example 3:
Input: A = "aa", B = "aa"
Output: true
Example 4:
Input: A = "aaaaaaabc", B = "aaaaaaacb"
Output: true
Example 5:
Input: A = "", B = "aa"
Output: false
Here's a starting point:


class Solution:
def buddyStrings(self, A, B):
# Fill this in.

print Solution().buddyStrings('aaaaaaabc', 'aaaaaaacb')
# True
print Solution().buddyStrings('aaaaaabbc', 'aaaaaaacb')
# False
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 691 Views, 14575 Search Bots | 109 Words Subscribe to Feed Burner

Related Articles

  1. Spreadsheet Columns
  2. Daily Interview Problem: Queue Using Two Stacks
  3. [Daily Problem] Move Zeros
  4. First and Last Indices of an Element in a Sorted Array
  5. A trick for getting good at coding interviews FASTER
  6. CPU Utilization
  7. Plus One
  8. Algorithm Interview: No Adjacent Repeating Characters
  9. Daily Interview Problem: Given two arrays, write a function to compute their intersection.
  10. Daily Interview Problem: Maximum Profit From Stocks

Comments (0)

Your Email (Domain Part Not Exposed):

Your Comments:

Privately By Mail Colors More Smileys S x y @

Verification (Click Image 2 Refresh):

    Be the first one to comment this page !


Page Edited: October 30 2020 14:21:09 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />