Leetcode OJ S_06

Source: Internet
Author: User

1  Public classSolution {2 3      Public Static voidMain (string[] args) {4String s = "paypalishiring";5String res = CONVERT (S, 4);6 System.out.println (res);7     }8 9     /**Ten * Numrows=1 and numrows=2 for special cases One      */ A      Public StaticString Convert (String s,intnumrows) { -String res = ""; -         intL =s.length (); the         if(L = = 0) { -             return""; -         } -  +         if(L > 0 && L <=numrows) { -             returns; +         } A  at         if(NumRows = = 1) { -             returns; -         } -  -         //Col is the number of columns -         intcol = L/(2 * numRows-2); in         intremainder = l% (2 * numRows-2); -         if(Remainder >= 0 && remainder <=numrows) { toCol = 2 * col + 1; +         } -         if(Remainder >numrows) { theCol = 2 * col + 2; *         } $ Panax Notoginseng         //temp is a secondary array -         int[] temp =New int[col]; theTemp[0] = 1; +          for(inti = 1; I < col; i++) { ATemp[i] = 2 * I * (numRows-1)-temp[i-1]; the         } +          for(inti = 0; i < numrows; i++) { -             if(i = = 0) { $                 intj = 0; $                  while(2 * J * (NUMROWS-1) <l) { -Res + = S.charat (2 * j * (numRows-1)); -J + +; the                 } -                 Continue;Wuyi             } the             if(i = = NumRows-1) { -                 intj = 0; Wu                  while((2 * j + 1) * (NUMROWS-1) <l) { -Res + = S.charat ((2 * j + 1) * (numRows-1)); AboutJ + +; $                 } -                 Continue; -             } -              for(intk = 0; K < Col; k++) { A                 if(k = = 0 && i <l) { +Res + =S.charat (i); the                     Continue; -                 } $                  the                 if(k%2==0){ the                     if(temp[k]+i-1<l) { theRes + = S.charat (temp[k]+i-1); the                         Continue; -                     } in                 } the                  the                 if(k% 2 = = 1) { About                     if(Temp[k]-i + 1 <l) { theRes + = S.charat (Temp[k]-i + 1); the                         Continue; the                     } +                 } -                  Break; the             }Bayi  the         } the  -         returnRes; -     } the}

Ideas:

Leetcode OJ S_06

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.