[ create a new paste ] login | about

Link: http://codepad.org/6Ox1pyAD    [ raw code | output | fork ]

C++, pasted on Mar 27:
#include <iostream>

using std::cout;
using std::cin;
using std::ios;
using std::cerr;
using std::endl;

#include <stdio.h>

#include <fstream>

using namespace std;

using std::ifstream;
using std::ofstream;

#include <cstdlib>

#include <math.h>

#include <algorithm>    // std::fill
#include <vector>       // std::vector





class Solution {
  public:
  int lengthOfLongestSubstring(string s) {
	  const int ASCII_MAX = 255;
	  int last[ASCII_MAX];
	  int start = 0;
	  fill(last, last + ASCII_MAX, -1);
	  int max_len = 0;
	  
	  for (int i = 0; i < s.size(); i++) {
		  if (last[s[i]] >= start) {
			  max_len = max(i - start, max_len);
			  start = last[s[i]] + 1;
		  }
		  last[s[i]] = i;
	  }
	  
	  return max((int)s.size() - start, max_len);
  }
  };




//##############################################################################
int main() { // M A I N   P R O G R A M
//##############################################################################	
  int i, j, q, l;
  int counter;
  double temptemp;

  
  int numnum = 0;

  Solution s; 
  
  system("pause");
  return 0;
} // int main()


Output:
1
2
3
4
5
6
cc1plus: warnings being treated as errors
t.cpp: In member function 'int Solution::lengthOfLongestSubstring(std::string)':
Line 40: warning: comparison between signed and unsigned integer expressions
Line 41: warning: array subscript has type 'char'
Line 43: warning: array subscript has type 'char'
Line 45: warning: array subscript has type 'char'


Create a new paste based on this one


Comments: