From 29412bed6f3eca1a6a93d1a01b8759348e94166c Mon Sep 17 00:00:00 2001 From: Sushant Sinha Date: Thu, 14 Jan 2021 13:59:41 +0530 Subject: [PATCH 1/7] Create _881.java --- .../java/com/fishercoder/solutions/_881.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/com/fishercoder/solutions/_881.java diff --git a/src/main/java/com/fishercoder/solutions/_881.java b/src/main/java/com/fishercoder/solutions/_881.java new file mode 100644 index 0000000000..64c752e304 --- /dev/null +++ b/src/main/java/com/fishercoder/solutions/_881.java @@ -0,0 +1,26 @@ +package com.fishercoder.solutions; + +public class _881 { + public static class Solution1 { + public int numRescueBoats(int[] people, int limit) { + Arrays.sort(people); + int end = people.length - 1; + int start = 0; + int boatcount = 0; + while (end >= start) { + if (people[end] == limit) { + end--; + boatcount++; + } else if (people[end] + people[start] <= limit) { + start++; + end--; + boatcount++; + } else { + end--; + boatcount++; + } + } + return boatcount; + } + } +} From 7a9ea8edbdc261b2c3160f3203957bda2dc38d54 Mon Sep 17 00:00:00 2001 From: Sushant Sinha Date: Sun, 31 Jan 2021 14:42:42 +0530 Subject: [PATCH 2/7] Update _881.java please check once --- src/main/java/com/fishercoder/solutions/_881.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/fishercoder/solutions/_881.java b/src/main/java/com/fishercoder/solutions/_881.java index 0775c20b3c..2eda0b499f 100644 --- a/src/main/java/com/fishercoder/solutions/_881.java +++ b/src/main/java/com/fishercoder/solutions/_881.java @@ -1,3 +1,5 @@ +package com.fishercoder.solutions; + import java.util.ArrayList; import java.util.List; import java.util.TreeMap; @@ -79,4 +81,4 @@ public int numRescueBoats(int[] people, int limit) { } } -} \ No newline at end of file +} From e301bdbcb530ed1875e139fd00690ed770e989a1 Mon Sep 17 00:00:00 2001 From: Sushant Sinha Date: Tue, 10 Aug 2021 20:47:46 +0800 Subject: [PATCH 3/7] Add files via upload --- ... Check If String Is a Prefix of Array.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 1961. Check If String Is a Prefix of Array.java diff --git a/1961. Check If String Is a Prefix of Array.java b/1961. Check If String Is a Prefix of Array.java new file mode 100644 index 0000000000..edbc75fc9c --- /dev/null +++ b/1961. Check If String Is a Prefix of Array.java @@ -0,0 +1,21 @@ +package com.fishercoder.solutions; + +public class _1961{ + +public class Solution1 { + public boolean isPrefixString(String s, String[] words) { + + String t=""; + int i=0; + + while(t.length() Date: Tue, 10 Aug 2021 18:20:20 +0530 Subject: [PATCH 4/7] Delete 1961. Check If String Is a Prefix of Array.java --- ... Check If String Is a Prefix of Array.java | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 1961. Check If String Is a Prefix of Array.java diff --git a/1961. Check If String Is a Prefix of Array.java b/1961. Check If String Is a Prefix of Array.java deleted file mode 100644 index edbc75fc9c..0000000000 --- a/1961. Check If String Is a Prefix of Array.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.fishercoder.solutions; - -public class _1961{ - -public class Solution1 { - public boolean isPrefixString(String s, String[] words) { - - String t=""; - int i=0; - - while(t.length() Date: Tue, 10 Aug 2021 20:59:22 +0800 Subject: [PATCH 5/7] Add files via upload --- ... Check If String Is a Prefix of Array.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/com/fishercoder/solutions/1961. Check If String Is a Prefix of Array.java diff --git a/src/main/java/com/fishercoder/solutions/1961. Check If String Is a Prefix of Array.java b/src/main/java/com/fishercoder/solutions/1961. Check If String Is a Prefix of Array.java new file mode 100644 index 0000000000..761a735354 --- /dev/null +++ b/src/main/java/com/fishercoder/solutions/1961. Check If String Is a Prefix of Array.java @@ -0,0 +1,21 @@ +package com.fishercoder.solutions; + +public class _1961{ + public class Solution1 { + public boolean isPrefixString(String s, String[] words) { + + String t=""; + int i=0; + + while(t.length() Date: Fri, 18 Mar 2022 09:27:40 +0530 Subject: [PATCH 6/7] 316 has difficulty level: Medium --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d93d98dbf8..321a8c008c 100644 --- a/README.md +++ b/README.md @@ -1031,7 +1031,7 @@ _If you like this project, please leave me a star._ ★ | 319 |[Bulb Switcher](https://leetcode.com/problems/bulb-switcher/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_319.java) | |Medium| Brainteaser | 318 |[Maximum Product of Word Lengths](https://leetcode.com/problems/maximum-product-of-word-lengths/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_318.java) | |Medium| | 317 |[Shortest Distance from All Buildings](https://leetcode.com/problems/shortest-distance-from-all-buildings/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_317.java) | |Hard| -| 316 |[Remove Duplicate Letters](https://leetcode.com/problems/remove-duplicate-letters/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_316.java) | |Hard| Stack, Recursion, Greedy +| 316 |[Remove Duplicate Letters](https://leetcode.com/problems/remove-duplicate-letters/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_316.java) | |Medium| Stack, Recursion, Greedy | 315 |[Count of Smaller Numbers After Self](https://leetcode.com/problems/count-of-smaller-numbers-after-self/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_315.java) | |Hard| Tree | 314 |[Binary Tree Vertical Order Traversal](https://leetcode.com/problems/binary-tree-vertical-order-traversal/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_314.java) | |Medium| HashMap, BFS | 313 |[Super Ugly Number](https://leetcode.com/problems/super-ugly-number/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_313.java) | |Medium| From 9c424116247618051797dad7c6f399a55efa9909 Mon Sep 17 00:00:00 2001 From: Sushant Sinha Date: Fri, 18 Mar 2022 09:43:55 +0530 Subject: [PATCH 7/7] added 1081 (same as 316) --- _1081.java | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 _1081.java diff --git a/_1081.java b/_1081.java new file mode 100644 index 0000000000..9e0ea691ec --- /dev/null +++ b/_1081.java @@ -0,0 +1,44 @@ +package com.fishercoder.solutions; + +import java.util.*; + +// same as 316. Remove Duplicate Letters +// from https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/_316.java + +public class _1002 { + public class Solution1 { + public String smallestSubsequence(String s) { + int[] res = new int[26]; //will contain number of occurences of character (i+'a') + boolean[] visited = + new boolean[26]; //will contain if character (i+'a') is present in current result Stack + char[] ch = s.toCharArray(); + for (char c : ch) { //count number of occurences of character + res[c - 'a']++; + } + Deque st = new ArrayDeque<>(); // answer stack + int index; + for (char c : ch) { + index = c - 'a'; + res[index]--; //decrement number of characters remaining in the string to be analysed + if (visited[index]) { + //if character is already present in stack, dont bother + continue; + } + //if current character is smaller than last character in stack which occurs later in the string again + //it can be removed and added later e.g stack = bc remaining string abc then a can pop b and then c + while (!st.isEmpty() && c < st.peek() && res[st.peek() - 'a'] != 0) { + visited[st.pop() - 'a'] = false; + } + st.push(c); //add current character and mark it as visited + visited[index] = true; + } + + StringBuilder sb = new StringBuilder(); + //pop character from stack and build answer string from back + while (!st.isEmpty()) { + sb.insert(0, st.pop()); + } + return sb.toString(); + } + } +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy