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

Related Articles

  1. Algorithm Interview Question: Find the Single Element in an Array of Duplicates
  2. Daily Interview Problem: Longest Substring With K Distinct Characters
  3. Daily Interview Problem: Deepest Node in a Binary Tree
  4. Daily Interview Problem: Queue Using Two Stacks
  5. Find Missing Numbers in an Array
  6. New Vulnerabilities (CVE-2016-4581) have been detected in CentOS/RHEL/CloudLinux 7
  7. Palindrome Integers
  8. Algorithm Interview: Convert Roman Numerals to Decimal
  9. Spreadsheet Columns
  10. Daily Interview Problem: Count Number of Unival Subtrees

Comments (0)

    Be the first one to comment this page !


Page Edited: May 11 2024 14:36:49 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />