summaryrefslogtreecommitdiff
path: root/week1/StringReverse.cs
blob: 2d09b0fd39b6e13524cca765ff85949a3c155cb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;

namespace ALGA {
	public class StringReverse {
		public static String string_reverse(String s) {
			if (s.Length == 0) return s;
			return s[s.Length - 1] + string_reverse(s.Substring(0, s.Length - 1));
		}

		public static bool is_palindrome(String s) {
			for (int front = 0; front < s.Length; front++) {
				int back = s.Length - 1 - front;
				if (s[front] != s[back]) return false;
			}
			return true;
		}
	}
}