• 检查两个字符串是否相等


    此博客链接:

    检查两个字符串是否相等

    题目链接:https://leetcode-cn.com/problems/check-if-two-string-arrays-are-equivalent/

    题目

    给你两个字符串数组 word1 和 word2 。如果两个数组表示的字符串相同,返回 true ;否则,返回 false 。

    数组表示的字符串 是由数组中的所有元素 按顺序 连接形成的字符串。

    示例 1:

    输入:word1 = ["ab", "c"], word2 = ["a", "bc"]
    输出:true
    解释:
    word1 表示的字符串为 "ab" + "c" -> "abc"
    word2 表示的字符串为 "a" + "bc" -> "abc"
    两个字符串相同,返回 true
    示例 2:

    输入:word1 = ["a", "cb"], word2 = ["ab", "c"]
    输出:false
    示例 3:

    输入:word1 = ["abc", "d", "defg"], word2 = ["abcddefg"]
    输出:true
     

    提示:

    1 <= word1.length, word2.length <= 103
    1 <= word1[i].length, word2[i].length <= 103
    1 <= sum(word1[i].length), sum(word2[i].length) <= 103
    word1[i] 和 word2[i] 由小写字母组成

    题解

    把两个字符串数组分别转成字符串,然后比较是否相等。

    代码

    
    
    class Solution {
        public boolean arrayStringsAreEqual(String[] word1, String[] word2) {
            String s1="";
            String s2="";
            for(int i=0;i<word1.length;i++){
                s1+=word1[i];
            }
            for(int i=0;i<word2.length;i++){
                 s2+=word2[i];
            }
            if(s1.equals(s2)){
                return true;
            }
            return false;
        }
    }
     

    结果

    出来混总是要还的
  • 相关阅读:
    HDU 4389 X mod f(x)
    SRM 400(1-250pt, 1-500pt)
    FZU 2113 Jason的特殊爱好
    POJ 3208 Apocalypse Someday
    HDU 4734 F(x)
    HDU 3555 Bomb
    HDU 2089 不要62
    poj2488(A Knight's Journey)
    poj3267(The Cow Lexicon)
    poj2513(Colored Sticks)
  • 原文地址:https://www.cnblogs.com/ping2yingshi/p/14772954.html
Copyright © 2020-2023  润新知