Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.99 KB | None | 0 0
  1. class Solution : MonotonicClock {
  2.     private var c1 by RegularInt(0)
  3.     private var c2 by RegularInt(0)
  4.     private var c3 by RegularInt(0)
  5.  
  6.     private var d1 by RegularInt(0)
  7.     private var d2 by RegularInt(0)
  8.     private var d3 by RegularInt(0)
  9.  
  10.     override fun write(time: Time) {
  11.         d1 = time.d1
  12.         d2 = time.d2
  13.         d3 = time.d3
  14.  
  15.         // write right-to-left
  16.         c3 = time.d3
  17.         c2 = time.d2
  18.         c1 = time.d1
  19.     }
  20.  
  21.     override fun read(): Time {
  22.         val vc1 = c1
  23.         val vc2 = c2
  24.         val vc3 = c3
  25.  
  26.         val vd3 = d3
  27.         val vd2 = d2
  28.         val vd1 = d1
  29.  
  30.  
  31.         return if (vc1 == vd1) {
  32.             if (vc2 == vd2) {
  33.                 if (vc3 == vd3) {
  34.                     Time(vc1, vc2, vc3)
  35.                 } else {
  36.                     Time(vc1, vc2, vd3)
  37.                 }
  38.             } else {
  39.                 Time(vc1, vd2, 0)
  40.             }
  41.         } else {
  42.             return Time(vd1, 0, 0)
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement