Ad

Just added name space std.

Code
Diff
  • #include <string>
    #include <string_view>
    using namespace std;
    string reverse_string(string_view word){
      return {word.rbegin(), word.rend()};
    }
    • #include <string>
    • #include <string_view>
    • std::string reverse_string(std::string_view word){
    • using namespace std;
    • string reverse_string(string_view word){
    • return {word.rbegin(), word.rend()};
    • }
Arrays

just added the namespace to reduce the code length a bit;

Code
Diff
  • #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <cassert>
    using namespace std;
    int unique_sum(const vector<int>& n) {
      auto nums = n;
      sort(nums.begin(), nums.end(), [](int a, int b) {
        return a < b;
      });
      int sum = 0;
      for(size_t i = 0; i < nums.size(); i++) {
        if(nums[i] == nums[i+1] || nums[i] == nums[i-1]) {
          continue;
        } else {
          sum += nums[i];
        }
      }
      return sum;
    }
    • #include <iostream>
    • #include <vector>
    • #include <algorithm>
    • #include <cassert>
    • int unique_sum(const std::vector<int>& n) {
    • using namespace std;
    • int unique_sum(const vector<int>& n) {
    • auto nums = n;
    • std::sort(nums.begin(), nums.end(), [](int a, int b) {
    • sort(nums.begin(), nums.end(), [](int a, int b) {
    • return a < b;
    • });
    • int sum = 0;
    • for(size_t i = 0; i < nums.size(); i++) {
    • if(nums[i] == nums[i+1] || nums[i] == nums[i-1]) {
    • continue;
    • } else {
    • sum += nums[i];
    • }
    • }
    • return sum;
    • }

Changed the for loop for a string builder. It's a little bit obscure but does still work.

Code
Diff
  • public class ReverseString {
      public static String reverseString(String word) {
        StringBuilder result = new StringBuilder();
        result.append(word);// adds the word to the string
        result.reverse();// you know REVERSES it 
        return result.toString();
        }
    }
    • public class ReverseString {
    • public static String reverseString(String word) {
    • String reversedWord = "";
    • for (int i = 0; i < word.length(); i++) {
    • reversedWord = word.charAt(i) + reversedWord;
    • StringBuilder result = new StringBuilder();
    • result.append(word);// adds the word to the string
    • result.reverse();// you know REVERSES it
    • return result.toString();
    • }
    • return reversedWord;
    • }
    • }

You only forgot to acctually call the method so your code does work!