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

Related Articles

  1. [Daily Problem] Course Prerequisites
  2. Algorithm Interview Question: Find the Single Element in an Array of Duplicates
  3. ImageMagick Vulnerabilities -  CVE-2016–3714
  4. Binary Tree Level with Minimum Sum
  5. Spreadsheet Column Title
  6. Compare Version Numbers
  7. Detect Linked List Cycle
  8. Reverse a Directed Graph
  9. Daily Interview Problem: Get all Values at a Certain Height in a Binary Tree
  10. Algorithm Interview Question: Symmetric k-ary 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="index, follow">