Leetcode 187: Repeated DNA Sequences

Source: Internet
Author: User

Leetcode 187: Repeated DNA Sequences
Total Accepted:1161Total Submissions:6887

All DNA is composed of a series of nucleus otides abbreviated as A, C, G, and T, for example: "ACGAATTCCG ". when studying DNA, it is sometimes useful to identify repeated sequences within the DNA.

Write a function to find all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule.

For example,

Given s = "aaaaacccccaaaaaccccaaaaagggttt", Return: ["AAAAACCCCC", "CCCCCAAAAA"].

[Analysis]

The HASHMAP method exceed space limit.

Because there are only four letters, you can create your own hashkey. Each two BITS corresponds to an incoming character. If the value exceeds 20 BITS, that is, 10 characters are retained, only 20 BITS are retained.

[Note]

1. (hash <2) + map. get (c) symbol priority, <must be included.


public class Solution {    public List
 
   findRepeatedDnaSequences(String s) {        List
  
    res = new ArrayList
   
    ();        if(s==null || s.length() < 11) return res;        int hash = 0;                Map
    
      map = new HashMap
     
      ();        map.put('A', 0);        map.put('C', 1);        map.put('G', 2);        map.put('T', 3);                Set
      
        set = new HashSet
       
        (); Set
        
          unique = new HashSet
         
          (); for(int i=0; i
          
           

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.