commit 63ae98196da1bf92088c2cead76fcf69ab39d48c
parent ff3ff0b5c5ac73e356ffbf46724bdf28f6210f7b
Author: Jack Sangdahl <jack@pngu.org>
Date: Thu, 18 Jun 2026 13:37:31 -0600
1344. angle between hands of a clock
Diffstat:
2 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/angle_between_clock_hands.c b/angle_between_clock_hands.c
@@ -0,0 +1,27 @@
+// 1344. Angle Between Hands of a Clock
+#include "leetcode.h"
+
+/*
+ * given two numbers, 'hour' and 'minutes', return the smaller angle (in
+ * degrees) formed between the 'hour' and the 'minute' hand. answers within
+ * 10^-5 of the actual value will be accepted.
+ */
+
+double angleClock(int hour, int minutes) {
+ double min = minutes * 6;
+ double hr = hour * 30 + (double)minutes / 2;
+ double diff = fabs(hr - min);
+ return fmin(diff, 360 - diff);
+}
+
+int main() {
+ double r1 = angleClock(12, 30);
+ double r2 = angleClock(3, 30);
+ double r3 = angleClock(3, 15);
+ printf("%f\n", r1);
+ assert(r1 == 165);
+ printf("%f\n", r2);
+ assert(r2 == 75);
+ printf("%f\n", r3);
+ assert(r3 == 7.5);
+}
diff --git a/angle_between_clock_hands.py b/angle_between_clock_hands.py
@@ -0,0 +1,19 @@
+# 1344. Angle Between Hands of a Clock
+
+"""
+given two numbers, 'hour' and 'minutes', return the smaller angle (in
+degrees) formed between the 'hour' and the 'minute' hand. answers within
+10^-5 of the actual value will be accepted.
+"""
+
+
+class Solution:
+ def angleClock(self, hour: int, minutes: int) -> float:
+ return min(abs(30 * hour - 5.5 * minutes), 360 - abs(30 * hour - 5.5 * minutes))
+
+
+if __name__ == "__main__":
+ obj = Solution()
+ print(obj.angleClock(hour=12, minutes=30))
+ print(obj.angleClock(hour=3, minutes=30))
+ print(obj.angleClock(hour=3, minutes=15))