Run Code
|
Code Wall
|
Users
|
Misc
|
Feedback
|
About
|
Login
|
Theme
|
Privacy
Anagrams
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//Title of this code #include <iostream> #include <map> #include <string> using namespace std; bool areAnagrams(const string& s1, const string& s2) { if (s1.length() != s2.length()) return false; map<char, int> m; for (int i = 0; i < s1.length(); ++i) { if (m.find(s1[i]) == m.end()) m[s1[i]] = 1; else ++m[s1[i]]; if (m.find(s2[i]) == m.end()) m[s2[i]] = -1; else --m[s2[i]]; } typename map<char, int>::iterator it; for (it = m.begin(); it != m.end(); ++it) if (it->second > 0) return false; return true; } int main() { std::cout << areAnagrams("abac","baca"); }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.42 sec, absolute running time: 0.14 sec, cpu time: 0 sec, memory peak: 3 Mb, absolute service time: 0.58 sec
fork mode
|
history
|
discussion
1