Problem Statement
If X and Y are two Strings of equal length N, then the difference between them is defined as the number of indices i where the i-th character of X and the i-th character of Y are different. For example, the difference between the words "ant" and "art" is 1. You are given two Strings, A and B, where the length of A is less than or equal to the length of B. You can apply an arbitrary number of operations to A, where each operation is one of the following:
Choose a character c and add it to the beginning of A.
Choose a character c and add it to the end of A.
Apply the operations in such a way that A and B have the same length and the difference between them is as small as possible. Return this minimum possible difference.
Definition
Class:
DifferentStrings
Method:
minimize
Parameters:
String, String
Returns:
int
Method signature:
int minimize(String A, String B)
(be sure your method is public)
Constraints
-
A and B will each contain between 1 and 50 characters, inclusive.
-
A and B will both contain only lowercase letters ('a'-'z').
-
The length of A will be less than or equal to the length of B.
Examples
0)
"koder"
"topcoder"
Returns: 1
You can prepend "top" to "koder" and you'll get "topkoder". The difference between "topkoder" and "topcoder" is 1.
1)
"hello"
"xello"
Returns: 1
A and B already have the same length so you cannot add any characters to A.
2)
"abc"
"topabcoder"
Returns: 0
3)
"adaabc"
"aababbc"
Returns: 2
4)
"giorgi"
"igroig"
Returns: 6
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
只将相等的情况作出来了,不相等的时候想了很久没有想通.
分享到:
- 2009-05-28 00:40
- 浏览 831
- 评论(0)
- 论坛回复 / 浏览 (0 / 1216)
- 查看更多
相关推荐
“一日三省”,2012 有道难题-网易创新大赛参赛作品,an Android App by Candy Group。
有道词典-每日英语.pdf
2012年有道难题资格赛题目,答案是我自己做的,不保证对
保险行业互联网保险探讨:混沌有道-20200603-国信证券-17页.pdf
4-网易有道-有道智能硬件的高效测试探索-刘哲.pdf
2010年网易有道难题 资格赛试题 共3套
《Linux C/C++ 一码农有道教程》是一门专为初学者设计的课程,通过系统性地讲解Linux操作系统和C/C++编程语言的基础知识和应用技巧,帮助学员快速掌握开发Linux应用程序的能力。课程包括理论与实践相结合的教学方式...
有道英文写作批改工具 您可以在任意网页上,通过有道写作-浏览器扩展解析各类输入框、文本框中英文内容的拼写、语法、样式、词级润色等不足,并根据智能建议进行修改,实现完美写作。1、智能识别100多种错误类型,...
有道-有道招股说明书(英文)-2020.6-372页精品报告2020.pdf
语言:中文 (简体) 有道翻译增加全屏和导出功能 有道翻译增加全屏和导出功能。需要手动翻页到底,然后再导出完整的翻译。
教(学)案-天下有道-丘也不与易也.doc
防疫有道-安心加无接触式通行解决方案.docx
Enterprise(有道文档翻译-原文)1
### 1.公司里面项目的工作流程? 首先我们会拿到产品给的PRD(需求文档)开一个需求评审的会议,目的在于看看需求哪些能实现,时间上面是否允许, 需求确定,对于我们研发组就开始分配工作任务,产品的研发到测试再...
1.get和post的区别 \1. get 是向服务器发送一条查看类型的请求,post是提交数据的请求 \2. get请求的入参是可以在url上看到的,相对来说安全系数较低,post是在自己的body体内发送 \3....\4....
《融资有道-中小企业融资操作技巧》.ppt
CHAdeMO-1.2-2nd DRAFT-en_r1 Copy(有道文档翻译-英译中结果).docx