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, 14521 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, 14521 Search Bots | 109 Words Subscribe to Feed Burner

Related Articles

  1. Algorithm Interview Question: Nth Fibonacci Number
  2. How to Play WAV music under DOS?
  3. Find Pythagorean Triplets
  4. Linode Support Ticket 10029540 - Other - Important Notice Regarding Ubuntu 17.10 Image
  5. Daily Interview Problem: Buddy Strings
  6. Daily Interview Problem: Count Number of Unival Subtrees
  7. Fix Brackets
  8. Daily Interview Problem: Find the Number of Islands
  9. [Daily Problem] Move Zeros
  10. Algorithm Interview: Lowest Common Ancestor of 2 Nodes in Binary Tree

Comments (0)

    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" />