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

Related Articles

  1. Spreadsheet Column Title
  2. New Vulnerabilities (CVE-2016-4581) have been detected in CentOS/RHEL/CloudLinux 7
  3. Daily Interview Problem: Minimum Removals for Valid Parenthesis
  4. Daily Interview Problem: Room scheduling
  5. Algorithm Interview: Subarray With Target Sum
  6. Daily Interview Problem: Validate Binary Search Tree
  7. [Daily Problem] Witness of The Tall People
  8. Autorun.inf Virus Protection
  9. Daily Interview Problem: Distribute Bonuses
  10. [Daily Problem] Add two numbers as a linked list

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