diff --git a/2D_Array/readme.md b/2D_Array/readme.md index 74f031c3a..5aa604c3f 100644 --- a/2D_Array/readme.md +++ b/2D_Array/readme.md @@ -13,6 +13,7 @@ Due to the fact that the elements of 2D arrays can be random accessed. Similar t * Checking Teoplitz Matrix Algorithm ----> [Java](/Code/Java/Toeplitz.java) * Clockwise Rotation ----> [C++](/Code/C++/2d_matrix_rotation_90degree_clockwise.cpp) * Inverse of a Matrix ----> [Java](/Code/Java/matrixop_inverse.java) +* Longest Substring Without Repeating Characters ----> [Java](/Code/Java/Longest_Substring.java) * Matrix Operations ----> [C++](/Code/C++/matrix_operations.cpp) * Multiplication of two Matrices ----> [Java](/Code/Java/matrixop_mul.java) * Overall Median of Matrix ---> [Java](/Code/Java/overall_median_matrix.java) @@ -20,5 +21,5 @@ Due to the fact that the elements of 2D arrays can be random accessed. Similar t * Spiral Print ----> [C++](/Code/C++/spiral_print.cpp) * Staircase Search ----> [C++](/Code/C++/staircase_search.cpp) * Substraction of two Matrices ----> [Java](/Code/Java/matrixop_sub.java) -* Transpose of a Matrix --->[Java](/Code/Java/transpose.java) | [Python](/Code/Python/Transpose_of_matrix.py) +* Transpose of a Matrix --->[Java](/Code/Java/transpose.java) | [](/Code//Transpose_of_matrix.py) * Wave Print ----> [C++](/Code/C++/wave_print.cpp) diff --git a/Code/Java/Longest_Substring.java b/Code/Java/Longest_Substring.java new file mode 100644 index 000000000..1235661ff --- /dev/null +++ b/Code/Java/Longest_Substring.java @@ -0,0 +1,47 @@ +// Question + +// 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. +// Example 4: + +// Input: s = "" +// Output: 0 + +// ***************************************************************************************************** + + +// Solution + +public class Longest Substring { + public int lengthOfLongestSubstring(String s) { + int len = s.length(); + int ans=0; + Map map = new HashMap<>(); + for(int j=0, i=0; j