zoukankan      html  css  js  c++  java
  • Valid Anagram

    题目:

    Given two strings s and t, write a function to determine if t is an anagram of s.

    For example,
    s = "anagram", t = "nagaram", return true.
    s = "rat", t = "car", return false.

    Note:
    You may assume the string contains only lowercase alphabets.

    Follow up:
    What if the inputs contain unicode characters? How would you adapt your solution to such case?

    解析:

    我的做法,注意string类支持大多数容器的操作

    1 class Solution {
    2 public:
    3     bool isAnagram(string s, string t) {
    4         sort(s.begin(),s.end());
    5         sort(t.begin(),t.end());
    6         return s==t;
    7     }
    8 };
  • 相关阅读:
    c++ 01
    unix c 11
    unix c 10
    unix c 09
    unix c 08
    unix c 07
    unix c 06
    unix c 05
    unix c 04
    Petrozavodsk Summer Training Camp 2017
  • 原文地址:https://www.cnblogs.com/raichen/p/4939626.html
Copyright © 2011-2022 走看看