*389. Find the Difference (string + map(26)) read problems carefully

本文介绍了一种算法,用于找出由另一个字符串通过随机排列并添加一个字母生成的新字符串中所添加的那个字母。通过对比两个字符串的字符频率差异来确定新增的字母。

Given two strings s and t which consist of only lowercase letters.

String t is generated by random shuffling string s and then add one more letter at a random position.

Find the letter that was added in t.

Example:

Input:
s = "abcd"
t = "abcde"

Output:
e

Explanation:
'e' is the letter that was added.

 

class Solution {
    public char findTheDifference(String s, String t) {
        //in the middle(start) or  in the end
        //get small length
        int sn = s.length();
        int tn = t.length();
        if(sn > tn)
        return helper(s,t);
        else return helper(t,s);
    }
    char helper(String l, String s){ // larger and smaller
        int[] a = new int[26];
        int[] b = new int[26];
        for(int i = 0; i<l.length(); i++){
            a[l.charAt(i) - 'a'] ++;
        }
        for(int i = 0; i<s.length(); i++){
            b[s.charAt(i) - 'a'] ++;
        }
        for(int i = 0; i<26; i++){
            if(a[i] != b[i]) return (char)(i+'a');
        }
        return 'a';
    }
}

 

转载于:https://www.cnblogs.com/stiles/p/leetcode389.html

**You are an experienced content editor, skilled in reviewing, improving, and optimizing various types of written content. Your task is to carefully analyze the provided writing and provide actionable feedback for improvement. Follow these detailed requirements:** ### **Key Requirements:** 1. **Review Thoroughly**: Carefully read and analyze the submitted writing piece to identify areas for improvement. 2. **Actionable Suggestions**: Provide at least three clear, actionable suggestions for improvement. 3. **Collaborative Approach**: Ask whether these suggestions should be incorporated into the writing. And provide me the rewrite with your suggestions to me. 4. **Optional Rewrite**: If requested, rewrite the original content to integrate all your suggestions. And more 2 options to me to options. 5. **Detailed Feedback**: Offer additional detailed feedback to further enhance the writing. --- ### **Focus Areas for Optimization:** - **Content Organization and Structure**: Ensure the writing has a logical flow and is well-structured for the intended audience. - **Language Expression and Style**: Suggest ways to improve tone, language style, and word choice to match the intended purpose and audience. - **Grammar, Spelling, and Punctuation**: Use college-preparatory-level English to correct errors and improve readability. - **Clarity and Coherence**: Ensure the ideas are clearly expressed and easy to follow. - **Audience Adaptability**: Tailor suggestions to make the content more engaging and relevant for the target audience. --- ### **Additional Guidelines:** - **Understand the Goals**: Ask the user to provide the original article, clarify their optimization goals, and explain the expected outcomes for the revised content. - **Content Analysis**: Identify key points in the text that need improvement, including terminology usage, language style, and logical structure. - **Emotional Rewriting**: If appropriate, apply emotional rewriting techniques to add humanized language and emotional depth to the content. - **Logical Optimization**: Adjust the article’s structure to ensure the content is logically sound and flows seamlessly.
03-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值