Strings

fancy character array

Longest Substring Without Repeating Characters

Given a string s, find the length of the longest substring without repeating characters
 
Example 1:

Input: s = "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
Example 2:

Input: s = "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.
Example 3:

Input: s = "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3.
Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.
public class Solution {

	static public int lengthOfLongestSubstring(String s) {
		int result = 0;
		Set<Character> charSet = new HashSet();
		int windowStart = 0;
		for (int windowEnd = 0; windowEnd < s.length(); windowEnd++) {
	// if the character at right pointer is duplicate, keep removing
	// character at left pointer until the duplicate character is removed.
			while (charSet.contains(s.charAt(windowEnd))) {
				charSet.remove(s.charAt(windowStart));
				windowStart++;
			}
	// add the character at the right pointer to the set
			charSet.add(s.charAt(windowEnd));
	// check if the current substring length is maximum
			result = Math.max(result, windowEnd - windowStart + 1);
		}
		return result;
	}

	public static void main(String[] args) {
		System.out.println(lengthOfLongestSubstring("abcadef"));
	}
}

Reverse String

Reverse Words in a String III

Valid Anagram

Ransom Note

First Unique Character in a String

Longest Substring Without Repeating Characters

Check Palindrome

Check string is subsequence of one another

Check if two strings are anagram

Leftmost Repeating character

Leftmost non repeating character

Reverse words in string

Pattern Searching in String for ALL CASES

Pattern Searching String in DISTINCT

Rapin Karp Alogrithm

KMP Algorithm (Part 1 : Constructing LPS Array)

KMP Agorithm (Part 2 : Complete Algorithm)

Check whether strings is rotated

Check if Strings are Rotations

Lexicographic Rank of a String

Longest Substring with Distinct Characters

Last updated