在一个字符串(1<=字符串长度<=10000,全部由大小写字母组成)中找到第一个只出现一次的字符,并返回它的位置


// test20.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<string.h>
#include<deque>

using namespace std;

class Solution {
public:
	int FirstNotRepeatingChar(string str) {
		if (str == "")
			return -1;
		int site = 0;
		int flag = 0;
		for (int i = 0;i < str.length();i++)
		{
			char ch = str[i];
			for (int j = 0;j < str.length();j++)
			{
				if (i != j) //i和j相同的话就是比较的同一个字符
				{
					if (ch == str[j]) break;
					if (j == str.length() - 1) flag = 1; //已经找完所有的数据
				}
			
			}
			if (flag == 1)
			{
				site = i+1;
				break;
			}
		}
		return site;
	}
};
int main()
{
	
	Solution so;
	//int count = so.FirstNotRepeatingChar("wangdanwang");
	int count = so.FirstNotRepeatingChar("");
	cout << count << endl;
	
	
	
	cout << endl;
	return 0;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM