From 3a61a7206b8625354061a1912a0ae0e0c4dee760 Mon Sep 17 00:00:00 2001 From: omprakash72810 <91782649+omprakash72810@users.noreply.github.com> Date: Sun, 31 Oct 2021 00:40:47 +0530 Subject: [PATCH] Create javaSolutionTwoKeyboard.java --- 2-Keys-Keyboard/javaSolutionTwoKeyboard.java | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 2-Keys-Keyboard/javaSolutionTwoKeyboard.java diff --git a/2-Keys-Keyboard/javaSolutionTwoKeyboard.java b/2-Keys-Keyboard/javaSolutionTwoKeyboard.java new file mode 100644 index 0000000..ea40cdf --- /dev/null +++ b/2-Keys-Keyboard/javaSolutionTwoKeyboard.java @@ -0,0 +1,22 @@ +//https://leetcode.com/problems/2-keys-keyboard/ + +class Solution { + public int minSteps(int n) { + + if(n==0 ||n==1) return 0; + if(n==2) return 2; + + return 2+solve(n,1,2); + } + public static int solve(int n,int copy,int len){ + if(len==n) return 0; + + if(len>n) return 100000; + + int copyPaste=2+solve(n,len,len+len); + int paste=1+solve(n,copy,len+copy); + + return Math.min(copyPaste,paste); + + } +}