How can I print out all possible letter combinations a given phone number can represent?

前端 未结 30 2310
逝去的感伤
逝去的感伤 2020-12-22 18:01

I just tried for my first programming interview and one of the questions was to write a program that given a 7 digit telephone number, could print all possible combinations

30条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-22 18:51

    Oracle SQL: Usable with any phone number length and can easily support localization.

    CREATE TABLE digit_character_map (digit number(1), character varchar2(1));
    
    SELECT replace(permutations,' ','') AS permutations
    FROM (SELECT sys_connect_by_path(map.CHARACTER,' ') AS permutations, LEVEL AS lvl
          FROM digit_character_map map 
          START WITH map.digit = substr('12345',1,1)
          CONNECT BY   digit = substr('12345',LEVEL,1))
    WHERE lvl = length('12345');
    

提交回复
热议问题