Find char sequence consists of same chars but in different order
2013-08-10 22:13
148 查看
Using two maps one processes ++ and the other processes -- operation;
#include <stdlib.h> char a[] = {'a','b','c','d','e'}; char b[] = {'a','b','d','d','e'}; int map[128]; void compare(char* a,char* b, int len){ int i; for(i = 0; i < len; i++){ map[a[i]]++; } for(i = 0; i < len; i++){ map[b[i]]--; } } int isEqual(){ int i = 0; for(; i < 256; i++){ if(map[i] != 0){ return -1; } } return 1; } int main(){ compare(a, b, 5); int result = isEqual(); printf("%d", result); }
相关文章推荐
- It is not possible to run two different versions of ASP.NET in the same IIS process:IIS
- 两种方法 Find inorder succ of BST
- Given a sequence of numbers (or array).Find the maximum distance between all the same numbers.
- 1.求整数最大的连续0的个数 BinaryGap Find longest sequence of zeros in binary representation of an integer.
- Ch4.5: find the (in-order tranversely) successor of a node in BST.
- 数组空间Given a sequence of numbers (or array).Find the maximum distance between all the same numbers.
- 'WHERE' is the same of 'on' in mysql(many times,but not always)
- Find the substring of length 3 which is present in the reverse order from the string
- It is not possible to run two different versions of ASP.NET in the same IIS process
- It is not possible to run two different versions of ASP.NET in the same IIS process.问题的解决
- This installation of RMagick was configured with ImageMagick 6.5.5 but ImageMagick 6.5.7-8 is in use
- Reference to Different Versions of the Same Assembly
- Values of attribute "level" not equal in different manifest snippets.
- query specified join fetching, but the owner of the fetched association was not present in the select list
- Ch2-5: find the beginning of loop in a circular linked list---two solutions
- C语言中不同类型的循环(Different types of loops in C)
- Find common characters in a set of strings
- [LeetCode] Find the k-th Smallest Element in the Union of Two Sorted Arrays
- Different Types of Pension Plans can help in your old days
- Ruby: Sorting an array of strings, in alphabetical order, that includes some arrays of strings