Posts

Showing posts with the label exam

Remove k digits

class Solution: def removeKdigits(self, num: str, k: int) -> str:     if len(num) == k:#no need to search, just return 0         return str(0)          point = 0 #use the point to traverse the num     while(k>0 and point < len(num)-1):         if num[point] > num[point+1]: #from left to right, each time we check if the digit that is larger than the digit behind             num = num[:point]+num[point+1:] #if so, delete that digit             k-=1             if point!=0:#except point equals to 0, we step back one digit                 point-=1             continue #jump the point+=1 statement         point+=1      if k == 0:#num[:-k] is not valid if k==0         return  str(i...

Dicegame

< html >      < head >      < script   type = "text/JavaScript" >       var   total1 = 0 ;       var   total2 = 0 ;       function   rollDice1 ()      {          var   die1 , die2 , d1 , d2 ;          die1 = document . getElementById ( "die1" );       die2 = document . getElementById ( "die2" );       status1 = document . getElementById ( "status1" );       scoreof1  =  document . getElementById ( "scoreof2" );       d1 = Math . floor ( Math . random ()*  6  ) +  1 ;       d2 = Math . floor ( Math . random ()*  6  ) +  1 ;      ...