commit 8f78322147243074914168617fe2a440044df57f
parent 878bf8e845aeb1be57accc531b1ff4dd45896145
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date: Sun, 16 Apr 2023 22:29:22 -0500
Completed remove duplicates in dart
Diffstat:
2 files changed, 74 insertions(+), 0 deletions(-)
diff --git a/longest-substring-without-repeating-characters/longest-substring.dart b/longest-substring-without-repeating-characters/longest-substring.dart
@@ -0,0 +1,37 @@
+import 'dart:io';
+
+
+//Longest substring without repeating characters
+//Runtime: 805ms Beats: 10.32%
+//Memory: 173.7MB Beats: 23.87%
+
+void main(){
+ Solution sol = new Solution();
+ stdout.write("Input your string to find longest substring without repeating characters: ");
+ String input = stdin.readLineSync()!;
+ print(sol.lengthOfLongestSubstring(input));
+}
+class Solution {
+ int lengthOfLongestSubstring(String s) {
+ int output = 0;
+ String current = "";
+ for(int i = 0 ; i < s.length ; ++i){
+ current = s[i];
+ for(int x = i + 1; x < s.length ; ++x){
+ if(current.contains(s[x])){
+ if(current.length > output){
+ output = current.length;
+ }
+ break;
+ }
+ else{
+ current += s[x];
+ }
+ }
+ if(current.length > output){
+ output = current.length;
+ }
+ }
+ return output;
+ }
+}
diff --git a/remove-duplicates-from-sorted-array/remove-duplicates.dart b/remove-duplicates-from-sorted-array/remove-duplicates.dart
@@ -0,0 +1,37 @@
+//Given an input list remove duplicate values.
+//Leetcode was dumb on this one and had to use some stupid side effect crap
+//what I did was get all unique values in the list by creating a set which
+//innately only stores unique values then switching that set back to a list.
+//I would not have needed this much code if they let me use the .toList method
+//for the set.
+
+//Runtime: 262ms Beats: 100%
+//Memory: 145.3MB Beats: 45.26%
+
+void main(){
+ Solution sol = new Solution();
+ List<int> nums = [0 , 3, 4, 5, 6,6,6,7,8,9,9,6,5,3,2];
+ //Init list
+ print(nums);
+ //Shorten list
+ sol.removeDuplicates(nums);
+ //New list
+ print(sol.num_list);
+}
+
+class Solution {
+ List<int> num_list = [];
+
+ int removeDuplicates(List<int> nums) {
+ Set<int> nums_set = nums.toSet();
+ int count = 0;
+ for(var i in nums_set){
+ nums[count] = i;
+ count += 1;
+ }
+ for(int i = 0; i < nums_set.length; ++i){
+ num_list.add(nums[i]);
+ }
+ return nums_set.length;
+ }
+}