Skip to content

Commit

Permalink
#33 Updating the test cases correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
debojyoti-majumder committed Jun 17, 2019
1 parent b10c055 commit b2bf0b0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 51 deletions.
2 changes: 2 additions & 0 deletions 2019Q2/leetcode011.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// Issue id: 34

#include <vector>

#include "gtest/gtest.h"
#include "gmock/gmock.h"

namespace Leetcode011 {
using namespace std;
Expand Down
52 changes: 2 additions & 50 deletions 2019Q2/leetcode767.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,59 +55,11 @@ namespace Leetcode767 {
class Solution {
private:
string _inputString;

int getAdjacentIndex() {
auto index { -1 };
auto strLength { _inputString.length() };

for( size_t i=0; i<strLength-1; i++ ) {
if( _inputString[i] == _inputString[i+1] ) {
index = i;
break;
}
}

return index;
}

int getCandidateChar(char ch, size_t lastSwapIndex) {
int index { -1 };

for( size_t i=lastSwapIndex; i<_inputString.length(); i++ ) {
if( _inputString[i] != ch ) {
index = i;
break;
}
}

return index;
}

public:
string reorganizeString(string S) {
string retValue {""};
_inputString = S;
int lastIndex {0};

auto len { S.size() };

for( size_t i=0; i<len-1; i++ ) {
auto index = getAdjacentIndex();

if( index == -1 ) {
retValue = _inputString;
break;
}

auto swIndex = getCandidateChar(_inputString[i], lastIndex);
if( swIndex != -1 ) {
lastIndex = swIndex + 1;
auto tmp { _inputString[index+1] };
_inputString[index+1] = _inputString[swIndex];
_inputString[swIndex] = tmp;
}
}


return retValue;
}
};
Expand All @@ -125,6 +77,6 @@ namespace Leetcode767 {

GTEST_TEST(Leet767, TLECase1) {
Solution s;
ASSERT_THAT(s.reorganizeString("kkkkzrkatkwpkkkktrq"), "");
ASSERT_NE(s.reorganizeString("kkkkzrkatkwpkkkktrq"), "");
}
}
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "gtest/gtest.h"
#include "CodeWars/prob101.hpp"
#include "2019Q2/leetcode011.hpp"
#include "2019Q2/leetcode767.hpp"

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
Expand Down

0 comments on commit b2bf0b0

Please sign in to comment.